public SpecialityLeasingModel GetSpecialityLeasingData()
        {
            SpecialityLeasingModel   specialityLeasingModel = new SpecialityLeasingModel();
            List <SpecialityLeasing> specialityLeasings     = new List <SpecialityLeasing>();
            List <SpecialProject>    specialProjects        = new List <SpecialProject>();
            DataSet data = DBConnection.GetData("GetSpecialityLeasing");

            foreach (DataRow row in data.Tables[0].Rows)
            {
                SpecialityLeasing obj = new SpecialityLeasing();
                obj.Tenant = !String.IsNullOrEmpty(row["Tenant"].ToString()) ? row["Tenant"].ToString() : string.Empty;
                obj.SpecialityLeasingId = new Guid(row["SpecialityLeasingId"].ToString());
                obj.Sector          = !String.IsNullOrEmpty(row["Sector"].ToString()) ? row["Sector"].ToString() : string.Empty;
                obj.UnitNo          = !String.IsNullOrEmpty(row["UnitNo"].ToString()) ? row["UnitNo"].ToString() : string.Empty;
                obj.Gla             = !String.IsNullOrEmpty(row["Gla"].ToString()) ? row["Gla"].ToString() : string.Empty;
                obj.Term            = !String.IsNullOrEmpty(row["Term"].ToString()) ? row["Term"].ToString() : string.Empty;
                obj.GrossRentBudget = !String.IsNullOrEmpty(row["GrossRentBudget"].ToString()) ? row["GrossRentBudget"].ToString() : string.Empty;
                obj.GrossRentActual = !String.IsNullOrEmpty(row["GrossRentActual"].ToString()) ? row["GrossRentActual"].ToString() : string.Empty;
                obj.SalesPercentage = !String.IsNullOrEmpty(row["SalesPercentage"].ToString()) ? row["SalesPercentage"].ToString() : string.Empty;
                obj.Comments        = !String.IsNullOrEmpty(row["Comments"].ToString()) ? row["Comments"].ToString() : string.Empty;
                specialityLeasings.Add(obj);
            }
            foreach (DataRow row in  data.Tables[1].Rows)
            {
                SpecialProject obj = new SpecialProject();
                obj.ProjectId = new Guid(row["ProjectId"].ToString());
                obj.Title     = !String.IsNullOrEmpty(row["Title"].ToString()) ? row["Title"].ToString() : string.Empty;
                obj.Content   = !String.IsNullOrEmpty(row["Content"].ToString()) ? row["Content"].ToString() : string.Empty;
                specialProjects.Add(obj);
            }
            specialityLeasingModel.specialityLeasings = specialityLeasings;
            specialityLeasingModel.specialProjects    = specialProjects;
            return(specialityLeasingModel);
        }
 public ActionResult SpecialityEdit(FormCollection form)
 {
     if (!string.IsNullOrEmpty(Session["username"] as string))
     {
         try
         {
             SpecialityLeasingModel   specialityLeasingModel = new SpecialityLeasingModel();
             List <SpecialityLeasing> lstleasing             = new List <SpecialityLeasing>();
             List <SpecialProject>    lstprojects            = new List <SpecialProject>();
             for (int i = 1; i <= 6; i++)
             {
                 SpecialityLeasing obj = new SpecialityLeasing();
                 obj.Tenant          = form["Tenant" + i];
                 obj.Sector          = form["Sector" + i];
                 obj.UnitNo          = form["UnitNo" + i];
                 obj.Gla             = form["Gla" + i];
                 obj.Term            = form["Term" + i];
                 obj.GrossRentBudget = form["GrossRentBudget" + i];
                 obj.GrossRentActual = form["GrossRentActual" + i];
                 obj.SalesPercentage = form["SalesPercentage" + i];
                 obj.Comments        = form["comment" + i];
                 lstleasing.Add(obj);
             }
             for (int i = 1; i <= 4; i++)
             {
                 SpecialProject obj = new SpecialProject();
                 obj.Title   = form["Title" + i];
                 obj.Content = form["Content" + i];
                 lstprojects.Add(obj);
             }
             specialityLeasingModel.specialityLeasings = lstleasing;
             specialityLeasingModel.specialProjects    = lstprojects;
             SpecialityLeasingData sdl = new SpecialityLeasingData();
             sdl.UpdateSpeciality(specialityLeasingModel);
             return(RedirectToAction("Index"));
         }
         catch (Exception ex)
         {
             return(View("Error", ex));
         }
     }
     else
     {
         return(RedirectToAction("Index", "Login"));
     }
 }
Пример #3
0
        public JsonResult Save(SpecialProjectViewModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.fileId) && Request.Files.Count == 0)
                {
                    return(Error("وارد کردن فایل تصویر الزامی است."));
                }

                var currentUser = GetAuthenticatedUser();

                if (model.id != null && model.id > 0)
                {
                    var entity = _context.SpecialProject.Single(x => x.StatusId != SpecialProjectStatus.Deleted.Id && x.Id == model.id);

                    if (Request.Files.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(entity.FileId))
                        {
                            AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "mainPage");
                        }

                        var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "mainPage");

                        model.fileId   = fileEntity.id;
                        model.fileName = fileEntity.fileName;
                    }
                    else if (string.IsNullOrEmpty(model.fileId) && !string.IsNullOrEmpty(entity.FileId))
                    {
                        if (!string.IsNullOrEmpty(entity.FileId))
                        {
                            AsefianFileContextHelper.DeleteFile(entity.FileId, entity.FileName, currentUser.id, "admin", "mainPage");
                        }
                    }

                    entity.Order        = model.order;
                    entity.FileId       = model.fileId;
                    entity.FileName     = model.fileName;
                    entity.Sku          = model.translations.Single(x => x.languageId == Language.Persian.Id).title.ToStandardPersian();
                    entity.StatusId     = model.statusId;
                    entity.ModifyUserId = currentUser.id;
                    entity.ModifyDate   = GetDatetime();
                    entity.ModifyIp     = GetCurrentIp();

                    model.translations.ForEach(item =>
                    {
                        var entityItem = entity.TranslationList.SingleOrDefault(x => x.LanguageId == item.languageId);
                        if (entityItem != null)
                        {
                            entityItem.Title       = item.title.ToStandardPersian();
                            entityItem.Description = item.description.ToStandardPersian();
                        }
                        else
                        {
                            entityItem = new SpecialProjectTranslation()
                            {
                                SpecialProjectId = entity.Id,
                                LanguageId       = item.languageId,
                                Title            = item.title,
                                Description      = item.description.ToStandardPersian(),
                            };
                            _context.SpecialProjectTranslation.Add(entityItem);
                        }
                    });

                    _context.SaveChanges();

                    return(Success("اطلاعات پروژه های خاص با موفقیت ویرایش شد."));
                }
                else
                {
                    if (Request.Files.Count > 0)
                    {
                        var fileEntity = AsefianFileContextHelper.Save(Request.Files[0], currentUser.id, GetCurrentIp(), "admin", "mainPage");

                        model.fileId   = fileEntity.id;
                        model.fileName = fileEntity.fileName;
                    }
                    else
                    {
                        model.fileId   = null;
                        model.fileName = null;
                    }

                    var entity = new SpecialProject()
                    {
                        Order        = model.order,
                        FileId       = model.fileId,
                        FileName     = model.fileName,
                        Sku          = model.translations.Single(x => x.languageId == Language.Persian.Id).title.ToStandardPersian(),
                        StatusId     = model.statusId,
                        CreateUserId = currentUser.id,
                        ModifyUserId = currentUser.id,
                        CreateDate   = GetDatetime(),
                        ModifyDate   = GetDatetime(),
                        CreateIp     = GetCurrentIp(),
                        ModifyIp     = GetCurrentIp()
                    };
                    _context.SpecialProject.Add(entity);
                    model.translations.ForEach(item =>
                    {
                        var entityItem = entity.TranslationList.SingleOrDefault(x => x.LanguageId == item.languageId);
                        if (entityItem != null)
                        {
                            entityItem.Title       = item.title.ToStandardPersian();
                            entityItem.Description = item.description.ToStandardPersian();
                        }
                        else
                        {
                            entityItem = new SpecialProjectTranslation()
                            {
                                SpecialProjectId = entity.Id,
                                LanguageId       = item.languageId,
                                Title            = item.title,
                                Description      = item.description.ToStandardPersian(),
                            };
                            _context.SpecialProjectTranslation.Add(entityItem);
                        }
                    });
                    _context.SaveChanges();

                    return(Success("پروژه های خاص با موفقیت ایجاد شد."));
                }
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }