private void editChecklists(EmployerForm source, EmployerUser dest)
        {
            foreach (var vacancy in source.Vacancies.OrderBy(x => x.CreationDate))
            {
                var checklist = DataAccessLayer.GetById<Checklist>(vacancy.Id);
                if (checklist == null)
                {
            #if DEBUG
                    throw new HttpException(404, "Checklist not found");
            #endif
            #if RELEASE
                return;
            #endif
                }

                DataAccessLayer.ClearChecklist(checklist);

                foreach (var attribute in DataAccessLayer.GetAttributes(DataAccessLayer.Constants.EmployerChecklistType.Id))
                {
                    var attributeValue = new AttribValue
                    {
                        AttribId = attribute.Id,
                        ChecklistId = checklist.Id
                    };
                    switch (attribute.Code)
                    {
                        case Constants.SalaryCode:
                            attributeValue.Value = vacancy.Salary;
                            break;
                        case Constants.WorkCode:
                            attributeValue.Value = vacancy.Work;
                            break;
                        case Constants.AboutCode:
                            attributeValue.Value = vacancy.FullDescription;
                            break;
                        case Constants.StartWorkCode:
                            attributeValue.Value = vacancy.StartTime.ToPandaString();
                            break;
                        case Constants.EndWorkCode:
                            attributeValue.Value = vacancy.EndTime.ToPandaString();
                            break;
                        case Constants.CityCode:
                            attributeValue.Value = vacancy.City;
                            break;
                        case Constants.GenderCode:
                            attributeValue.Value = vacancy.Gender;
                            break;
                    }

                    checklist.AttrbuteValues.Add(attributeValue);
                }

            }
        }
        private void editMainParam(EmployerForm source, EmployerUser dest)
        {
            dest.Email = source.Email;
            dest.IsAdmin = source.IsAdmin;
            var checklist = dest.MainChecklist;
            if (checklist == null)
            {
            #if DEBUG
                throw new HttpException(404, "Checklist not found");
            #endif
            #if RELEASE
                return;
            #endif
            }

            var mainAlbum = dest.Albums.First();
            if (source.NewPhotos != null)
            {
                foreach (var photo in source.NewPhotos)
                {
                    DataAccessLayer.Create(new Photo
                    {
                        Album = DataAccessLayer.GetById<Album>(mainAlbum.Id),
                        SourceUrl = ImageCreator.SavePhoto(photo)
                    });
                }
            }

            DataAccessLayer.ClearChecklist(checklist);

            foreach (var attribute in DataAccessLayer.GetAttributes(DataAccessLayer.Constants.EmployerMainChecklistType.Id))
            {
                var attributeValue = new AttribValue
                {
                    AttribId = attribute.Id,
                    ChecklistId = checklist.Id
                };

                #region Big switch [TODO by code field]
                switch (attribute.Code)
                {
                    case Constants.AboutCode:
                        attributeValue.Value = source.About;
                        break;
                    case Constants.EmployerNameCode:
                        attributeValue.Value = source.EmployerName;
                        break;
                    case Constants.AddressCode:
                        attributeValue.Value = source.Address;
                        break;
                    case Constants.MobilePhoneCode:
                        attributeValue.Value = source.MobilePhone;
                        break;
                    case Constants.CityCode:
                        attributeValue.Value = source.City;
                        break;
                }
                #endregion

                checklist.AttrbuteValues.Add(attributeValue);
            }
        }
 public void Edit(EmployerForm source, EmployerUser dest)
 {
     editMainParam(source, dest);
     editChecklists(source, dest);
 }
        public ActionResult Edit(EmployerForm model, IEnumerable<HttpPostedFileBase> photos)
        {
            if (ModelState.IsValid)
            {
                model.NewPhotos = photos == null ? new List<HttpPostedFileBase>() : photos.Where(x => x != null);
                var user = DataAccessLayer.GetById<EmployerUser>(model.UserId);
                var editor = new EmployerEditor(DataAccessLayer);
                editor.Edit(model, user);
                DataAccessLayer.DbContext.SaveChanges();
                return new RedirectResult(string.Format("/Employer/Edit/{0}", model.UserId));
            }

            #if DEBUG
            throw new Exception("ModelState is invalid");
            #else
            return new EmptyResult();
            #endif
        }
 public ActionResult Edit(Guid id)
 {
     ViewBag.CityValues = DataAccessLayer.ListItemsFromDict(Constants.CityCode).
         OrderBy(x => x.Text)
         .ToList();
     var binder = new FormEmployerToUser(DataAccessLayer);
     var user = DataAccessLayer.GetById<EmployerUser>(id);
     var model = new EmployerForm();
     binder.InverseLoad(user, model);
     return View(model);
 }
Exemple #6
0
 public static EmployerForm Bind(DataAccessLayer dataAccessLayer, Guid userId)
 {
     var binder = new FormEmployerToUser(dataAccessLayer);
     var user = dataAccessLayer.GetById<EmployerUser>(userId);
     var model = new EmployerForm();
     binder.InverseLoad(user, model);
     return model;
 }