Beispiel #1
0
        public ActionResult Edit(Company model, long?id)
        {
            ViewData["pagename"] = "company";
            JsonResponse response = new JsonResponse();

            response.Message = ConstantUtil.MessageError;
            response.Status  = ConstantUtil.StatusFail;
            if (ModelState.IsValid)
            {
                try
                {
                    if (!string.IsNullOrEmpty(model.Image) &&
                        !System.IO.File.Exists(Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last()) &&
                        System.IO.File.Exists(Server.MapPath(TempPath) + model.Image.Split('/').Last()))
                    {
                        System.IO.File.Copy(Server.MapPath(TempPath) + model.Image.Split('/').Last(), Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last());
                        model.Image = UrlUtility.GetAbsoluteUrl(CompanyImagesPath + model.Image.Split('/').Last());
                    }
                    model.ModifiedBy   = CurrentUser;
                    model.ModifiedDate = DateTime.UtcNow;

                    var companyEntity = _companyService.Find(model.CompanyId);


                    companyEntity.CompanyName            = model.CompanyName;
                    companyEntity.ContactPerson          = model.ContactPerson;
                    companyEntity.Address1               = model.Address1;
                    companyEntity.Address2               = model.Address2;
                    companyEntity.State                  = model.State;
                    companyEntity.City                   = model.City;
                    companyEntity.Zip                    = model.Zip;
                    companyEntity.CountryID              = model.CountryID;
                    companyEntity.Phone                  = model.Phone;
                    companyEntity.Email                  = model.Email;
                    companyEntity.Active                 = model.Active;
                    companyEntity.CreatedDate            = DateTime.UtcNow;
                    companyEntity.ModifiedBy             = model.ModifiedBy;
                    companyEntity.ModifiedDate           = DateTime.UtcNow;
                    companyEntity.Image                  = model.Image;
                    companyEntity.VuforiaServerAccessKey = model.VuforiaServerAccessKey;
                    companyEntity.VuforiaServerSecretKey = model.VuforiaServerSecretKey;
                    companyEntity.VuforiaClientAccessKey = model.VuforiaClientAccessKey;
                    companyEntity.VuforiaClientSecretKey = model.VuforiaClientSecretKey;


                    companyEntity.ObjectState = ObjectState.Modified;
                    _companyService.Update(companyEntity);

                    bool success = _unitOfWorkAsync.SaveChanges() > 0;

                    if (success)
                    {
                        logging.Info("Company updated with name " + model.CompanyName);
                        response.Message   = "Company updated successfully";
                        response.Status    = ConstantUtil.StatusOk;
                        response.ReturnUrl = Url.Action("Index");
                    }
                }
                catch (Exception ex)
                {
                    logging.Error(ex.ToString());
                }
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult EditCompany(Company model, string returnUrl)
        {
            JsonResponse response = new JsonResponse();

            response.Message = ConstantUtil.MessageError;
            response.Status  = ConstantUtil.StatusFail;
            try
            {
                if (!string.IsNullOrEmpty(model.Image) &&
                    !System.IO.File.Exists(Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last()) &&
                    System.IO.File.Exists(Server.MapPath(TempPath) + model.Image.Split('/').Last()))
                {
                    System.IO.File.Copy(Server.MapPath(TempPath) + model.Image.Split('/').Last(), Server.MapPath(CompanyImagesPath) + model.Image.Split('/').Last());
                    model.Image = UrlUtility.GetAbsoluteUrl(CompanyImagesPath + model.Image.Split('/').Last());
                }

                var companyEntity = _companyService
                                    .Query(x => x.CompanyId == model.CompanyId)
                                    .Include(x => x.User)
                                    .Select().SingleOrDefault();

                companyEntity.CompanyId              = model.CompanyId;
                companyEntity.CompanyName            = model.CompanyName;
                companyEntity.ContactPerson          = model.ContactPerson;
                companyEntity.Address1               = model.Address1;
                companyEntity.Address2               = model.Address2;
                companyEntity.State                  = model.State;
                companyEntity.City                   = model.City;
                companyEntity.Zip                    = model.Zip;
                companyEntity.CountryID              = model.CountryID;
                companyEntity.Phone                  = model.Phone;
                companyEntity.Email                  = model.Email;
                companyEntity.UserName               = model.UserName;
                companyEntity.Active                 = model.Active;
                companyEntity.ModifiedBy             = CurrentUser;
                companyEntity.ModifiedDate           = DateTime.UtcNow;
                companyEntity.Image                  = model.Image;
                companyEntity.UserName               = companyEntity.User.UserName;
                companyEntity.VuforiaServerAccessKey = model.VuforiaServerAccessKey;
                companyEntity.VuforiaServerSecretKey = model.VuforiaServerSecretKey;
                companyEntity.VuforiaClientAccessKey = model.VuforiaClientAccessKey;
                companyEntity.VuforiaClientSecretKey = model.VuforiaClientSecretKey;


                _companyService.Update(companyEntity);

                bool success = _unitOfWorkAsync.SaveChanges() > 0;

                if (success)
                {
                    //Set the current culture if country changes
                    string countryCode = _companyService.FindCountry(model.CountryID).CountryCode2;
                    countryCode = string.IsNullOrEmpty(countryCode) ? "US" : countryCode;
                    var cultureInfo = CultureInfo.GetCultures(CultureTypes.AllCultures).Where(c => c.Name.EndsWith(countryCode)).FirstOrDefault();
                    cultureInfo = cultureInfo == null ? new CultureInfo("en-US") : cultureInfo;
                    Thread.CurrentThread.CurrentCulture       = cultureInfo;
                    ((User)Session["ActiveUser"]).CultureCode = cultureInfo.CompareInfo.Name;
                    ((User)Session["ActiveUser"]).Image       = model.Image;
                    Session["Photo"] = model.Image;
                    logging.Info("Profile updated successfully.");
                    response.Message   = "Profile updated successfully.";
                    response.Status    = ConstantUtil.StatusOk;
                    response.ReturnUrl = returnUrl;

                    var obj = _companyService.Find(model.CompanyId);

                    Session["CurrentCompany"] = obj;
                }
            }
            catch (Exception ex)
            {
                logging.Error(ex.ToString());
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }