Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a view with a lot of data that I want to keep them for DB - and ran indeed all data is saved in the DB excellent.
But when I uploaded to serve - and went to find his way to address all of a sudden he can not save your picture files. (With all the other data is also working out) and instead save and return to the screen of the index after clicking on the save he returns to the start screen (the first screen with which the site costs) without saving.
The error it gives in consol:
"Failed to load resource: the server Responded with a status of 500 (Internal Server Error)"


How do we fix the problem ??
Thanks in advance



the view:
HTML
@model CII.Web.Models.POIlangData

@{
    ViewBag.Title = "Edit POI";
    int langId = ViewBag.LangId;
    long POIId = ViewBag.POIId;
    @Html.Hidden("LanguageId", langId)
    @*@Html.Hidden("langId", langId)*@
    List<CII.Domain.Language> langlist = (List<CII.Domain.Language>)ViewData["languages"];
}
<script src="~/Scripts/carousel.js/lightbox.js"></script>
<script type="text/javascript">
    function readURL(input) {
        $('.newlink').remove();
        var count = $('#NumberofImages').val();
        if (input.files && input.files[0]) {
            for (var i = 0; i < input.files.length; i++) {
                var reader = new FileReader();
                $('#images').append('<input type="hidden" name="imageids[' + count + ']" value="' + input.files[i].name + '" />');
                $('#images').append('<input type="hidden" name="keep[' + count + ']" value="1"  data-imageid="' + count + '"/>');
                $('#images').append("<a id='link' class='newlink darken' ></a>");
                reader.onload = function (e) {
                    var count = $('#NumberofImages').val();
                    $('#link').append("<img id='image' class='img-rounded' src='" + e.target.result + "' data-imageid='" + count + "' width='80' height='80'/>");
                    $('#link').append('<span class="hoverText" data-imageid="' + count + '">Remove</span>');
                    $('#link').attr('id', 'link' + count);
                    $('#NumberofImages').val(++count);
                };
                reader.readAsDataURL(input.files[i]);
            }
            $('#noimage').remove();
        }
    }
    function ImageClick(val) {
        var clicked = 0;
        $('input[data-imageid]').each(function () {
            if ($(this).attr('data-imageid') == val) {
                clicked = $(this).val();
                if (clicked == 1)
                    $(this).val(0);
                else
                    $(this).val(1);
                clicked = $(this).val();
            }
        });
        if (clicked == 0) {
            $('img[data-imageid]').each(function () {
                if ($(this).attr('data-imageid') == val) {
                    $(this).css("opacity", "0.2");
                    $(this).unbind('mouseenter mouseleave');
                }
            });
            $('span[data-imageid]').each(function () {
                if ($(this).attr('data-imageid') == val)
                    $(this).text("Add");
            });
        }
        else {
            $('img[data-imageid]').each(function () {
                if ($(this).attr('data-imageid') == val) {
                    $(this).hover(function () { $(this).css("opacity", "0.4"); },
                        function () { $(this).css("opacity", "1"); });
                }
            });
            $('span[data-imageid]').each(function () {
                if ($(this).attr('data-imageid') == val)
                    $(this).text("Remove");
            });
        }
    }
    function setcategory() {
        var val = $('#CategoryId').val();
        $('[data-category]').each(function () {
            if ($(this).attr('data-category').indexOf('|' + val + '|') > -1)
                $(this).show();
            else
                $(this).hide();
        });
    }
    function setlanguage() {
        var val = $('#LanguageId').val();
        $('[data-Language]').each(function () {
            if ($(this).attr('data-Language').indexOf('|' + val + '|') > -1)
                if ($(this).prop("tagName") == "B")
                    $(this).css("color", "#6700ab");
                else
                    $(this).show();
            else
                if ($(this).prop("tagName") == "B")
                    $(this).css("color", "#0094ff");
                else
                    $(this).hide();
        });
    }
    function changelanguage(lang) {
        $('#LanguageId').val(lang);
        setlanguage();
    }
    //function readURL(input) {
    //    if (input.files && input.files[0]) {
    //        var reader = new FileReader();
    //        reader.onload = function (e) {
    //            $('#logoimg').attr('src', e.target.result);
    //            $('#logolink').attr('href', e.target.result);
    //        };
    //        reader.readAsDataURL(input.files[0]);
    //    }
    //}
    $(document).ready(function () {
        setlanguage();
        setcategory();
    });
</script>

<style>
    a.darken:hover img {
        opacity: 0.4;
    }

    a.darken:hover {
        display: inline-block;
        background: black;
        padding: 0;
        position: relative;
    }

    a.darken span {
        position: absolute;
        top: 10px;
        left: 10px;
        color: rgba(255, 255, 255, 0);
    }

    a.darken:hover span {
        color: #ff0000;
        font-size: 18px;
    }
</style>

@*זה לא היה בהערה*@
@*@if (Model.ChainId == 0)
    {
        <h2>
            Create New Chain
        </h2>}
    else
    {
        <h2>Edit</h2>
    }
    <h2>POI Edit</h2>*@

@using (Html.BeginForm("Edit", "POI", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()

    <input type="hidden" value=@Model.CategoryId id="CategoryId" />
    <input type="hidden" value=@Model.POIs_Lang id="langId" />

    <div class="form-horizontal">
        <h4>POIs</h4>
        <hr />
        <input hidden="hidden" id="id" value=@Model.POIId />
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.POIId)
        @Html.HiddenFor(model => model.LogoFileId)
        @Html.HiddenFor(model => model.ImageFileId)

        <div class="row">
            @*ממומלץ*@
            <div class="form-group col-md-8">
                @if (Model.ChainId == null)
                {
                    @Html.LabelFor(model => model.Recommended, new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.EditorFor(model => model.Recommended)
                        @Html.ValidationMessageFor(model => model.Recommended)
                    </div>
                }
                else
                {
                    @Html.HiddenFor(model => model.Recommended)
                }
            </div>

        </div>

        @*myCarousel*@
        <div class="row">
            <div class="col-xs-10">

                @*לוגו ותמונה*@
                <div class="row">
                    <div class="col-md-2">
                        @if (Model != null && Model.LogoFileId.HasValue)
                        {
                            <div class="form-group">
                                <label class="control-label col-md-2">@*POI logo*@</label>
                                <a class="col-md-10" href="@Url.RouteUrl("Media", new {id=Model.LogoFileId})" target="_blank"><img src="@Url.RouteUrl("Media", new {id=Model.LogoFileId})" width="100" height="100" /></a>
                            </div>
                        }

                        @if (Model != null && Model.ImageFileId.HasValue)
                        {
                            <div class="form-group">
                                <label class="control-label col-md-2">@*POI image*@</label>
                                <a class="col-md-10" href="@Url.RouteUrl("Media", new { id = Model.ImageFileId })" target="_blank"><img src="@Url.RouteUrl("Media", new { id = Model.ImageFileId})" width="100" height="100" /></a>
                            </div>
                        }

                    </div>

                    @*תמונה*@
                    <div class="col-xs-3">
                        <div class="form-group">
                            <div class="col-md-10">
                                <br />
                                <label class="control-label">Upload a new POI logo</label>
                                <input type="file" id="logo" class="form-control" name="logo" />
                                @if (Model != null && Model.LogoFileId.HasValue)
                                {
                                    <p class="help-block">The old image will be replaced !</p>
                                }
                            </div>
                        </div>


                        @* <div class="form-group">
                                <div class="col-md-10">
                                    <label class="control-label">Upload a new POI image</label>
                                    <input type="file" id="image" class="form-control" name="image" />
                                    @if (Model != null && Model.ImageFileId.HasValue)
                                    {
                                        <p class="help-block">The old image will be replaced !</p>
                                    }
                                </div>
                            </div>*@

                        <div class="form-group">
                            <div class="col-md-10">
                                <br />
                                <label class="control-label">Upload new Images</label>
                                <input type="file" id="imgfiles" class="form-control" name="imgfiles" multiple onchange="readURL(this);" />
                            </div>
                        </div>

                    </div>
                    <div class="col-xs-3">
                        @*עיר*@
                        <div class="form-group">
                            @Html.LabelFor(model => model.CityId, "City", new { @class = "control-label col-md-3" })
                            <div class="col-md-10">
                                @Html.DropDownListFor(model => model.CityId, ViewBag.CityId.Items as IEnumerable<SelectListItem>, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.CityId)
                            </div>
                        </div>

                        @*טלפון*@
                        <div class="form-group">
                            @Html.LabelFor(model => model.PhoneNumber, new { @class = "control-label col-md-4" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.PhoneNumber, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.PhoneNumber)
                            </div>
                        </div>






                        @*נקודת X,Y*@
                        <div class="form-group">
                            @Html.LabelFor(model => model.Latitude, new { @class = "control-label col-md-3" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.Latitude, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Latitude)
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.Longitude, new { @class = "control-label col-md-3" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.Longitude, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Longitude)
                            </div>
                        </div>

                    </div>
                    <div class="col-md-3">
                        @*טלפונים של הבית מלון*@
                        <div class="form-group" data-category="|5|">
                            @Html.LabelFor(model => model.PhoneNumber_Spa, new { @class = "control-label col-md-4" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.PhoneNumber_Spa, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.PhoneNumber_Spa)
                            </div>
                        </div>

                        <div class="form-group" data-category="|5|">
                            @Html.LabelFor(model => model.PhoneNumber_RoomServices, new { @class = "control-label col-md-4" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.PhoneNumber_RoomServices, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.PhoneNumber_RoomServices)
                            </div>
                        </div>

                        <div class="form-group" data-category="|5|">
                            @Html.LabelFor(model => model.PhoneNumber_Concierge, new { @class = "control-label col-md-4" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.PhoneNumber_Concierge, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.PhoneNumber_Concierge)
                            </div>
                        </div>

                        <div class="form-group" data-category="|5|">
                            @Html.LabelFor(model => model.HotelId, new { @class = "control-label col-md-4" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(model => model.HotelId, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.HotelId)
                            </div>
                        </div>
                    </div>

                    <div class="col-md-4">
                        @*תמונות*@
                        <div class="col-md-5">
                            <label class="control-label">City background Images</label>
                            <div id="images">
                                @{
                                int x = 0;
                                foreach (var img in Model.POIsImages)
                                {
                                    @Html.Hidden("imageids[" + x + "]", img.ImageId);
                                    <input type="hidden" name="keep[@x]" value="1" data-imageid="@x" />
                                    <a class="darken" >
                                        <img id="image" class="img-rounded" data-imageid="@x" src="@Url.RouteUrl("Media", new { id = img.FileId })" width="80" height="80" />
                                        <span class="hoverText" data-imageid="@x">Remove</span>
                                    </a>

                                    //x++;
                                }

                                @Html.Hidden("NumberofImages", x);
                                }
                            </div>
                            @if (Model.POIsImages.Count == 0)
                            {
                                <div id="noimage" class="text-center h3"><br /><br />No Images Uploaded</div>
                            }
                        </div>
                    </div>

                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="row">
                            <label class="col-md-2">Day: </label>
                            <div class="form-group col-md-4">
                                <div>
                                    @Html.TextBoxFor(model => model.OpenDay1, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.OpenDay1)
                                </div>
                            </div>

                            <label class="col-sm-1">-</label>
                            <div class="form-group col-md-4">
                                <div>
                                    @Html.TextBoxFor(model => model.EndDay1, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.EndDay1)
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-md-2">Day: </label>
                            <div class="form-group col-md-4">
                                <div>
                                    @Html.TextBoxFor(model => model.OpenDay2, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.OpenDay2)
                                </div>
                            </div>

                            <label class="col-sm-1">-</label>
                            <div class="form-group col-md-4">
                                <div>
                                    @Html.TextBoxFor(model => model.EndDay2, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.EndDay2)
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-5">
                        <div class="row">
                            <label class="col-md-2">Time: </label>
                            <div class="form-group col-md-4">
                                <div>
                                    @{
                                        List<SelectListItem> lstTime = new List<SelectListItem>();
                                        for(int i=0; i<12; i++)
                                        {
                                            lstTime.Add(new SelectListItem(){Text=i+":00", Value=i+":00"});
                                            lstTime.Add(new SelectListItem(){Text=i+":30", Value=i+":30"});
                                        }
                                    }
                                    @Html.DropDownListFor(model => model.OpenTime1,lstTime, new { @class = "form-control" });
                                    @Html.ValidationMessageFor(model => model.OpenTime1);

                                </div>
                            </div>

                            <label class="col-sm-1">--</label>
                            <div class="form-group col-md-4">
                                <div>
                                    @Html.TextBoxFor(model => model.CloseTime1, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.CloseTime1)
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-md-2">Time: </label>
                            <div class="form-group col-md-4">
                                <div>
                                    @Html.TextBoxFor(model => model.OpenTime2, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.OpenTime2)
                                </div>
                            </div>

                            <label class="col-sm-1">--</label>
                            <div class="form-group col-md-4">
                                <div>
                                    @Html.TextBoxFor(model => model.CloseTime2, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.CloseTime2)
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <div class="form-group">
                            <div class="col-md-offset-2 col-md-10">
                                <input type="submit" value="Save" class="btn btn-default" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        @*קטגוריה*@
        <div class="form-group" hidden="hidden">
            @Html.LabelFor(model => model.CategoryId, "Category", new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.CategoryId, ViewBag.CategoryId.Items as IEnumerable<SelectListItem>, new { onchange = "setcategory()", @class = "form-control" })
                @Html.ValidationMessageFor(model => model.CategoryId)
            </div>
        </div>




        @*תג

            <div class="form-group">
                @Html.LabelFor(model => model.Tags, new { @class = "control-label col-md-2" })
                <div class="col-md-10">

                    <select data-placeholder="Select some tags" id="tagsList" name="tagsList" multiple="multiple" class="chosen form-control">
                        @foreach (var item in ViewData["tagslist"] as List<CII.Domain.Tags_Lang>)
                        {
                            <option value="@item.TagId" selected="@Model.Tags.Select(s=>s.TagId).Contains(item.TagId)">@item.Text</option>
                        }
                    </select>
                </div>
            </div>
        *@


    </div>
    @*<input name="pois_lang" value="@Model.POIs_Lang" type="hidden" />*@
    <div class="container" style="tab-size:inherit">
        <ul class="nav nav-tabs">
            @for (int i = 0; i < langlist.Count; i++)
            {
                int xx = 0;
                string cssClass = "item active";

                @Html.Hidden("pois_lang[" + xx + "]", langlist[i].LanguageId);
                <li class="@cssClass">
                    @{
                       var plang = Model.POIs_Lang.FirstOrDefault(p => p.LanguageId == langlist[i].LanguageId);
                       if (plang != null)
                       {
                        <a >[__b data-language="|@langlist[i].LanguageId|"__]@langlist[i].Title</a>
                       }
                       else
                       {
                        <a >[__b data-language="|@langlist[i].LanguageId|"__]@langlist[i].Title</a>
                       }
                    }
                </li>

                       cssClass = "item";
                       xx++;
            }

        </ul>
    </div>
    <div>
        @for (int i = 0; i < langlist.Count; i++)
        {
            <table style="width:100%;">
                <tr>
                    <td>
                        @{
            var plang = Model.POIs_Lang.FirstOrDefault(p => p.LanguageId == langlist[i].LanguageId);
            @Html.Hidden("poilang[" + i + "].POIId", Model.POIId)
                            @Html.Hidden("poilang[" + i + "].LanguageId", langlist[i].LanguageId)

                            @*שם*@
                            <div class="form-group" data-language="|@langlist[i].LanguageId|">
                                @Html.Label("Name", new { @class = "control-label col-md-3" })
                                <div class="col-md-7">
                                    @Html.TextBox("poilang[" + i + "].Name", plang != null ? plang.Name : "", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.POIs_Lang.FirstOrDefault(p => p.LanguageId == langlist[i].LanguageId).Name)
                                </div>
                            </div>

                            @*כתובת*@
                            <div class="form-group" data-language="|@langlist[i].LanguageId|">
                                @Html.Label("Address", new { @class = "control-label col-md-3" })
                                <div class="col-md-7">
                                    @Html.TextBox("poilang[" + i + "].Address", plang != null ? plang.Address : "", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.Address)
                                </div>
                            </div>

                            @*תיאור*@
                            <div class="form-group" data-language="|@langlist[i].LanguageId|">
                                @Html.Label("Description", new { @class = "control-label col-md-3" })
                                <div class="col-md-7">
                                    @Html.TextArea("chainlang[" + i + "].Description", plang != null ? plang.Description : "", new { @class = "form-control", rows = "15" })
                                    @Html.ValidationMessageFor(model => model.POIs_Lang.FirstOrDefault(p => p.LanguageId == langlist[i].LanguageId).Description)
                                </div>
                            </div>
                        }
                    </td>
                    <td>
                        @if (Model != null && Model.AttachementId.HasValue)
                        {
                            <div class="form-group" data-language="|@langlist[i].LanguageId|">
                                <label class="control-label col-md-3">Attachment</label>
                                <a class="col-md-10" href="@Url.RouteUrl("Media", new {id=Model.AttachementId})" target="_blank">View Attachment</a>
                                <a class="col-md-10" href="#" >Delete Attachment</a>
                            </div>
                        }
                        <div class="form-group" data-language="|@langlist[i].LanguageId|">
                            <label class="control-label col-md-10">Upload a new Attachment </label>
                            <div class="col-md-8">
                                <input type="file" id="attachment" class="form-control" name="attachment" />
                                @if (Model != null && Model.AttachementId.HasValue)
                                {
                                    <p class="help-block">The old attachment will be replaced !</p>
                                }
                            </div>
                        </div>
                        @if (Model != null && Model.CouponAttachementId.HasValue)
                        {
                            <div class="form-group" data-language="|@langlist[i].LanguageId|">
                                <label class="control-label col-md-10">Coupon</label>
                                <a class="col-md-10" href="@Url.RouteUrl("Media", new {id=Model.CouponAttachementId})" target="_blank">View Coupon</a>
                                <a class="col-md-10" href="#" >Delete Coupon</a>
                            </div>
                        }

                        <div class="form-group" data-language="|@langlist[i].LanguageId|">
                            <label class="control-label col-md-10">Upload a new Coupon </label>
                            <div class="col-md-8">
                                <input type="file" id="coupon" class="form-control" name="coupon" />
                                @if (Model != null && Model.CouponAttachementId.HasValue)
                                {
                                    <p class="help-block">The old coupon will be replaced !</p>
                                }
                            </div>
                        </div>

                    </td>
                </tr>
            </table>
        }
    </div>
}


the controller:
C#
public ActionResult Edit([Bind(Include = "POIId,CategoryId,WebsiteUrl,PhoneNumber,PhoneNumber_Spa,PhoneNumber_RoomServices,PhoneNumber_Concierge,Latitude,Longitude,LogoFileId,Location,FromDate,ToDate,CityId,ChainId,Recommended,ImageFileId,HotelId,OpenDay1,EndDay1,OpenDay2,EndDay2,OpenTime1,CloseTime1,OpenTime2,CloseTime2")] POIs pois,
     ICollection<POIs_Lang> poilang,
     HttpPostedFileBase[] imgfiles, string[] imageids,
     int[] keep)
 {
     if (ModelState.IsValid)
     {
         if (pois.POIId == 0)
             pois=db.POIs.Add(pois);
         else
             db.Entry(pois).State = EntityState.Modified;
         foreach (var cl in poilang)
         {
             cl.POIId = pois.POIId;
             EditLang(cl, cl.POIId);
         }
         //save/remove images
         POIsImage img;
         if (keep != null)
         {
             Guid[] removedimgs = new Guid[keep.Count()];
             int r = 0;
             for (var x = 0; x < keep.Length; x++)
             {
                 if (keep[x] == 0)    //remove
                 {
                     long id;
                     if (long.TryParse(imageids[x], out id))
                     {
                         img = db.POIsImages.Find(id);
                         if (img != null)
                         {
                             db.POIsImages.Remove(img);
                             removedimgs[r++] = img.FileId;

                             db.SaveChanges();
                         }
                     }
                 }
             }
             r = 0;

             for (var x = 0; x < keep.Length; x++)
             {
                 if (keep[x] == 1)               //save
                     if (imgfiles.First() != null)
                     {
                         var file = imgfiles.Where(p => p.FileName == imageids[x]).FirstOrDefault();
                         if (file != null && file.ContentLength > 0)
                         {
                             img = new POIsImage();
                             img.POIId = pois.POIId;
                             img.DisplayOrder = x;
                             //if (img.FileId == null)
                             img.File = Domain.MediaServices.Save(removedimgs[r++], file, db);
                             //else
                             //    img.File = Domain.MediaServices.Save(img.FileId, file, db);
                             img=db.POIsImages.Add(img);
                         }
                     }
                 try
                 {
                  db.SaveChanges();
                 }
                 catch (Exception e)
                 {

                      Log.MyLog(e.Message.ToString(), "BeforeTheSaveChanges in poiContriller");
                 }
             }
         }
         if (Request.Files["logo"] != null && Request.Files["logo"].ContentLength > 0)
             pois.File = Domain.MediaServices.Save(pois.LogoFileId, Request.Files["logo"], db);
         pois.Location = LocationUtils.CreateLocation(pois.Latitude, pois.Longitude);
         int? catid = pois.CategoryId;
         return RedirectToAction("Index", new { catid = catid, cityid = pois.CityId });
     }

     ViewBag.CategoryId = new SelectList(db.Categories.Select(c => new { CategoryId = c.CategoryId, Name = c.Categories_lang.FirstOrDefault().CategoryName }), "CategoryId", "Name", pois.CategoryId);
     ViewBag.CityId = new SelectList(db.Cities.Select(c => new { CityId = c.CityId, Name = c.Cities_lang.FirstOrDefault().CityName }), "CityId", "Name", pois.CityId);
     ViewData["languages"] = db.Languages.OrderBy(l => l.LanguageId).ToList();

     POIlangData poi_lang_data = new POIlangData(pois);
     return View(poi_lang_data);//viewmodel
 }


the model:
C#
using CII.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CII.Web.Models
{
    public class POIlangData
    {
        public long POIId { get; set; }
        public int CategoryId { get; set; }
        public string WebsiteUrl { get; set; }
        public string PhoneNumber { get; set; }
        public string PhoneNumber_Spa { get; set; }
        public string PhoneNumber_RoomServices { get; set; }
        public string PhoneNumber_Concierge { get; set; }
        public Nullable<decimal> Latitude { get; set; }
        public Nullable<decimal> Longitude { get; set; }
        public Nullable<System.Guid> LogoFileId { get; set; }
        public System.Data.Entity.Spatial.DbGeography Location { get; set; }
        public Nullable<System.DateTime> FromDate { get; set; }
        public Nullable<System.DateTime> ToDate { get; set; }
        public int CityId { get; set; }
        public Nullable<long> ChainId { get; set; }
        public bool Recommended { get; set; }
        public Nullable<System.Guid> ImageFileId { get; set; }
        public Nullable<int> HotelId { get; set; }
        public Nullable<int> OpenDay1 { get; set; }
        public Nullable<int> EndDay1 { get; set; }
        public Nullable<int> OpenDay2 { get; set; }
        public Nullable<int> EndDay2 { get; set; }
        public Nullable<System.TimeSpan> OpenTime1 { get; set; }
        public Nullable<System.TimeSpan> CloseTime1 { get; set; }
        public Nullable<System.TimeSpan> OpenTime2 { get; set; }
        public string CloseTime2 { get; set; }

        public virtual Category Category { get; set; }
        public virtual File File { get; set; }
        public virtual ICollection<Intro> Introes { get; set; }
        public virtual ICollection<POIs_Lang> POIs_Lang { get; set; }
        public virtual ICollection<Tag> Tags { get; set; }
        public virtual ICollection<Tours_POIs> Tours_POIs { get; set; }
        public virtual ICollection<Users_POIs_Tours> Users_POIs_Tours { get; set; }
        public virtual City City { get; set; }
        public virtual Chain Chain { get; set; }
        public virtual File File1 { get; set; }
        public virtual ICollection<Activity> Activities { get; set; }
        public virtual ICollection<POIsImage> POIsImages { get; set; }

        public int LanguageId { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string Description { get; set; }
        public Nullable<System.Guid> AttachementId { get; set; }
        public Nullable<System.Guid> CouponAttachementId { get; set; }

        public virtual Language Language { get; set; }
        public virtual POIs POIs { get; set; }

        public POIlangData()
        {
            POIId = 0;
        }

        public POIlangData(POIs pois)
        {
            POIId = pois.POIId;
            CategoryId = pois.CategoryId;
            WebsiteUrl = pois.WebsiteUrl;
            PhoneNumber = pois.PhoneNumber;
            PhoneNumber_Spa = pois.PhoneNumber_Spa;
            PhoneNumber_RoomServices = pois.PhoneNumber_RoomServices;
            PhoneNumber_Concierge = pois.PhoneNumber_Concierge;
            Latitude = pois.Latitude;
            Longitude = pois.Longitude;
            LogoFileId = pois.LogoFileId;
            Location = pois.Location;
            FromDate = pois.FromDate;
            ToDate = pois.ToDate;
            CityId = pois.CityId;
            ChainId = pois.ChainId;
            Recommended = pois.Recommended;
            ImageFileId = pois.ImageFileId;
            HotelId = pois.HotelId;
            OpenDay1 = pois.OpenDay1;
            EndDay1 = pois.EndDay1;
            OpenDay2 = pois.OpenDay2;
            EndDay2 = pois.EndDay2;
            OpenTime1 = pois.OpenTime1;
            CloseTime1 = pois.CloseTime1;
            OpenTime2 = pois.OpenTime2;
            CloseTime2 = pois.CloseTime2;

            Category = pois.Category;
            File = pois.File;
            Introes = pois.Introes;
            POIs_Lang = pois.POIs_Lang;
            Tags = pois.Tags;
            Tours_POIs = pois.Tours_POIs;
            Users_POIs_Tours = pois.Users_POIs_Tours;
            City = pois.City;
            Chain = pois.Chain;
            File1 = pois.File1;
            Activities = pois.Activities;
            POIsImages = pois.POIsImages;
        }
        public POIlangData(POIs pois, POIs_Lang pois_lang)
        {
            POIId = pois.POIId;
            CategoryId = pois.CategoryId;
            WebsiteUrl = pois.WebsiteUrl;
            PhoneNumber = pois.PhoneNumber;
            PhoneNumber_Spa = pois.PhoneNumber_Spa;
            PhoneNumber_RoomServices = pois.PhoneNumber_RoomServices;
            PhoneNumber_Concierge = pois.PhoneNumber_Concierge;
            Latitude = pois.Latitude;
            Longitude = pois.Longitude;
            LogoFileId = pois.LogoFileId;
            Location = pois.Location;
            FromDate = pois.FromDate;
            ToDate = pois.ToDate;
            CityId = pois.CityId;
            ChainId = pois.ChainId;
            Recommended = pois.Recommended;
            ImageFileId = pois.ImageFileId;
            HotelId = pois.HotelId;
            OpenDay1 = pois.OpenDay1;
            EndDay1 = pois.EndDay1;
            OpenDay2 = pois.OpenDay2;
            EndDay2 = pois.EndDay2;
            OpenTime1 = pois.OpenTime1;
            CloseTime1 = pois.CloseTime1;
            OpenTime2 = pois.OpenTime2;
            CloseTime2 = pois.CloseTime2;

            Category = pois.Category;
            File = pois.File;
            Introes = pois.Introes;
            POIs_Lang = pois.POIs_Lang;
            Tags = pois.Tags;
            Tours_POIs = pois.Tours_POIs;
            Users_POIs_Tours = pois.Users_POIs_Tours;
            City = pois.City;
            Chain = pois.Chain;
            File1 = pois.File1;
            Activities = pois.Activities;
            POIsImages = pois.POIsImages;

            LanguageId = pois_lang.LanguageId;
            Name = pois_lang.Name;
            Address = pois_lang.Address;
            Description = pois_lang.Description;
            AttachementId = pois_lang.AttachementId;
            CouponAttachementId = pois_lang.CouponAttachementId;

            Language = pois_lang.Language;
            POIs = pois_lang.POIs;
        }
    }
}

the MediaServices:
C#
using Quickode.Media;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CII.Domain
{
    public class MediaRepository : IMediaRepository
    {
        public IMediaFile Save(IMediaFile file)
        {
            if (file == null) return file;
            using (check_in_israelEntities db = new check_in_israelEntities())
            {
                File f = db.Files.Create();
                f.FileId = file.FileId;
                db.Files.Add(f);
                db.SaveChanges();
            }
            return file;
        }

        public bool Delete(IMediaFile _file)
        {
            if (_file == null) return false;
            using (check_in_israelEntities db = new check_in_israelEntities())
            {

                db.Files.Remove(db.Files.Find(_file.FileId));
            }
            return true;
        }
    }

    public static class MediaServices
    {
        public static string GetPath(Guid id)
        {
            string folder = ConfigurationManager.AppSettings["Media.FolderPath"];
            string dir = Path.Combine(folder, id.ToString());
            foreach (var item in Directory.GetFiles(dir))
            {
                if (Path.GetFileNameWithoutExtension(item) == "file")
                    return item;
            }

            return string.Empty;
        }


        public static File Save(Guid? id, System.Web.HttpPostedFileBase file, check_in_israelEntities db)
        {


            //get folder
            string folder = ConfigurationManager.AppSettings["Media.FolderPath"];
            if (!id.HasValue || id.Value == Guid.Empty)//create new image
            {
                id = Guid.NewGuid();
                string dir = Path.Combine(folder, id.Value.ToString());
                Directory.CreateDirectory(dir);
                string ext = Path.GetExtension(file.FileName).Trim('.');
                file.SaveAs(Path.Combine(dir, "file." + ext));

            }
            //update existing image
            else
            {
                string dir = Path.Combine(folder, id.Value.ToString());
                if (!Directory.Exists(dir))
                    Directory.CreateDirectory(dir);
                foreach (var item in Directory.GetFiles(dir))
                {
                    System.IO.File.Delete(item);
                }
                string ext = Path.GetExtension(file.FileName).Trim('.');
                file.SaveAs(Path.Combine(dir, "file." + ext));
            }

            File f = db.Files.Find(id.Value);
            if (f == null)
            {
                f = db.Files.Create();
                f.FileId = id.Value;
                db.Files.Add(f);

            }

            return f;

        }
    }
}


[edit]Urgency deleted - OriginalGriff[/edit]
Posted
Updated 8-Sep-15 21:27pm
v3
Comments
OriginalGriff 9-Sep-15 3:15am    
Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.

And that isn't a good question: it's a code dump, with a tiny bit of text.
It doesn't tell us anything about your problem - I have no idea what "When you enter the address of the performance of a way it does not save images and the screen comes first." means. Remember that we can't see your screen, access your HDD, or read your mind.

And please do not use "I do not get along" or similar as your subject as it does not tell potential answerers what your problem is - that wastes their time if they know nothing about your problem. If you use a more descriptive title, you will get better focussed responses.

Use the "Improve question" widget to edit your question and provide better information.
Member 11919288 9-Sep-15 3:43am    
Thanks for Hharh- probably too nervous I was.
Improved question, hoping that now is the right ...
F-ES Sitecore 9-Sep-15 4:37am    
You're going to have to do some debugging to at least narrow down what the actual error is, and the line of code the error happens on. You can't post hundreds of lines of code that fails on something that is specific to an environment we don't have access to and expect someone to know the solution.

1 solution

"Failed to load resource: the server Responded with a status of 500 (Internal Server Error)" this means that the image is missing from the server or if you are getting this from IDE then the image is missing from your content or images folder.
 
Share this answer
 
Comments
Richard Deeming 16-Sep-15 14:32pm    
No - a "file not found" error would return a status of 404. Error 500 means there was an error running a server-side script.
Member 11919288 17-Sep-15 6:10am    
thank you!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900