コード例 #1
0
        public ActionResult Select()
        {
            string mode = Request.QueryString["Grid-mode"];

            if (!string.IsNullOrEmpty(mode))
            {
                return(this.RedirectToAction("Create"));
            }
            else
            {
                List <CountryVM> viewModels           = new List <CountryVM>();
                CountryBAL       balObject            = new CountryBAL();
                IQueryable <Entities.Country> entites = balObject.GetAll();
                foreach (Entities.Country entity in entites)
                {
                    CountryVM viewModel = new CountryVM();
                    viewModel.CountryId   = entity.CountryId;
                    viewModel.CountryName = entity.CountryName;
                    viewModel.Status      = entity.Status;
                    viewModel.Remark      = entity.Remark;
                    viewModels.Add(viewModel);
                }
                return(this.View("Index", new GridModel <CountryVM> {
                    Data = viewModels
                }));
            }
        }
コード例 #2
0
        public IResponseDTO EditCountry(CountryVM model)
        {
            try
            {
                var DbCountry   = _mapper.Map <Country>(model);
                var entityEntry = _CountryRepositroy.Update(DbCountry);
                int save        = _unitOfWork.Commit();

                if (save == 200)
                {
                    _response.Data     = model;
                    _response.IsPassed = true;
                    _response.Message  = "Ok";
                }
                else
                {
                    _response.Data     = null;
                    _response.IsPassed = false;
                    _response.Message  = "Not saved";
                }
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }
            return(_response);
        }
コード例 #3
0
        public string UpdateCountry(CountryVM country)
        {
            string countryId = string.Empty;

            SqlParameter[] parameters =
            {
                new SqlParameter {
                    ParameterName = "@Id", Value = country.Id
                },
                new SqlParameter {
                    ParameterName = "@Code", Value = country.Code
                },
                new SqlParameter {
                    ParameterName = "@Name", Value = country.Name
                },
                new SqlParameter {
                    ParameterName = "@SortOrder", Value = country.SortOrder
                },
                new SqlParameter {
                    ParameterName = "@IsActive", Value = country.IsActive
                },
                new SqlParameter {
                    ParameterName = "@UpdatedBy", Value = country.UpdatedBy
                }
            };

            countryId = Convert.ToString(DALHelper.ExecuteScalar("UpdateCountry", parameters));

            return(countryId);
        }
コード例 #4
0
        public ActionResult Create(CountryVM viewModel)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    Entities.Country entity = new Entities.Country();
                    entity.CountryId   = viewModel.CountryId;
                    entity.CountryName = viewModel.CountryName;
                    entity.Status      = viewModel.Status;
                    entity.Remark      = viewModel.Remark;

                    CountryBAL balObject = new CountryBAL();
                    balObject.Add(entity);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //AcademicYearBAL academicYearBAL = new AcademicYearBAL();
                    // viewModel.AcademicYears = from obj in academicYearBAL.GetAll() select new SelectListItem() { Text = obj.AcademicYearName, Value = obj.AcademicYearId.ToString() };
                    return(View(viewModel));
                }
            }
            catch
            {
                //AcademicYearBAL academicYearBAL = new AcademicYearBAL();
                // viewModel.AcademicYears = from obj in academicYearBAL.GetAll() select new SelectListItem() { Text = obj.AcademicYearName, Value = obj.AcademicYearId.ToString() };
                return(View(viewModel));
            }
        }
コード例 #5
0
        public ActionResult Edit(CountryVM viewModel)
        {
            try
            {
                // TODO: Add update logic here
                if (ModelState.IsValid)
                {
                    Entities.Country entity = new Entities.Country();
                    entity.CountryId   = viewModel.CountryId;
                    entity.CountryName = viewModel.CountryName;
                    entity.Status      = viewModel.Status;
                    entity.Remark      = viewModel.Remark;

                    CountryBAL balObject = new CountryBAL();
                    balObject.Edit(entity);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(viewModel));
                }
            }
            catch
            {
                return(View());
            }
        }
コード例 #6
0
        public IResponseDTO DeleteCountry(CountryVM model)
        {
            try
            {
                var DbCountry   = _mapper.Map <Country>(model);
                var entityEntry = _CountryRepositroy.Remove(DbCountry);

                int save = _unitOfWork.Commit();
                if (save == 200)
                {
                    _response.Data     = null;
                    _response.IsPassed = true;
                    _response.Message  = "Ok";
                }
                else
                {
                    _response.Data     = null;
                    _response.IsPassed = false;
                    _response.Message  = "Not saved";
                }
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + ex.Message;
            }
            return(_response);
        }
コード例 #7
0
        public IActionResult New(CountryVM model)
        {
            try
            {
                var obj = _context.Countries
                          .Where(x =>
                                 x.NameAr.Trim().ToLower() == model.NameAr.Trim().ToLower() &&
                                 x.NameEn.Trim().ToLower() == model.NameEn.Trim().ToLower())
                          .SingleOrDefault();

                if (obj == null &&
                    model.NameAr.Trim().Length > 0 && model.NameAr.Trim().Length > 0)
                {
                    Country country = new Country
                    {
                        NameAr = model.NameAr,
                        NameEn = model.NameEn
                    };
                    country.ImageUrl
                        = Helpers.FileHelper.Upload(model.FileUpload, _host.WebRootPath);
                    _context.Add(country);
                    _context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("Manage", "Country"));
            }
            return(RedirectToAction("Manage", "Country"));
        }
コード例 #8
0
        public IActionResult Country(CountryVM countryVM)
        {
            CountryVM_DataManager countryVM_DataManager = new CountryVM_DataManager();
            ModelStateDictionary  msd = CountryVM_DataManager.ValidateCountry(ref countryVM);

            //Model validation occurs prior to each controller action being invoked, and it's the action method's responsibility to inspect ModelState.IsValid and react appropriately.


            //Manual validation
            //After model binding and validation are complete, you may want to repeat parts of it. For example, a user may have entered text in a field expecting an integer, or you may need to compute a value for a model's property.
            //You may need to run validation manually.To do so, call the TryValidateModel

            //when TryUpdateModel()  is called it doesnot raise exceptions you should use ValidateModel Or TryValidateModel
            bool b = TryValidateModel(countryVM);

            foreach (string K in msd.Keys)
            {
                ModelStateEntry mse = null;
                msd.TryGetValue(K, out mse);
                ModelState.AddModelError(K, mse.Errors[0].ErrorMessage);
            }
            bool c = ModelState.IsValid;


            if (!c)
            {
                return(View(countryVM));
            }


            countryVM_DataManager.SaveCountry(countryVM);
            return(RedirectToAction("Country"));
        }
コード例 #9
0
        public CountryVM Get(int id)
        {
            CountryVM model = null;

            using (CountryOperation operation = new CountryOperation())
            {
                model = new CountryVM
                {
                    Country = operation.Get(id)
                };
            }
            try
            {
                model.Flag = File.ReadAllBytes(AppConfig.FlagPath + string.Format(model.Country.Flag, AppConfig.FlagResolution));
            }
            catch (DirectoryNotFoundException e)
            {
                Log4NetManager.Error("Bayrak klasörü bulunamadı", e);
            }
            catch (FileNotFoundException e)
            {
                Log4NetManager.Error("Bayrak dosyası bulunamadı", e);
            }
            return(model);
        }
コード例 #10
0
        public async Task <IActionResult> Edit([Bind("Id, Name, Code")] CountryVM country)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await service.UpdateCountryAsync(country.Adapt <CountryDTO>());
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CountryExists(country.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(country));
        }
コード例 #11
0
        public bool Add(CountryVM countryVm)
        {
            var entity = new Country();

            entity = ToCountryInsertEntity(countryVm);
            return(_countryDal.Add(entity));
        }
コード例 #12
0
        public async Task <CountryVM> PutAsync(CountryVM Country)
        {
            var newCountryVM = iMapper.Map <CountryVM, Country>(Country);
            var newCountry   = await unitOfWork.CountryRepository.AddOrUpdateAsync(newCountryVM);

            return(iMapper.Map <Country, CountryVM>(newCountry));
        }
コード例 #13
0
        private void RepopulateListsFromCacheSession(CountryVM model)
        {
            // Populate cached lists if they are empty. Will invoke service call
            CountryLookupListsCacheObject CachedLists = CacheManager.CountryListCache;

            // Retrieve any cached lists to model
        }
コード例 #14
0
        /// <summary>
        /// Private method to merge in the model
        /// </summary>
        /// <returns></returns>
        private CountryVM GetUpdatedModel()
        {
            CountryVM model = new CountryVM();

            RepopulateListsFromCacheSession(model);
            model.Message = "";

            if (SessionManager.CurrentCountry != null)
            {
                model.CountryItem = SessionManager.CurrentCountry;
            }

            //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING **************************
            bool result = TryUpdateModel(model);//This also validates and sets ModelState

            //*******************************************************************************************************************************
            if (SessionManager.CurrentCountry != null)
            {
                //*****************************************PREVENT OVER POSTING ATTACKS******************************************************
                //Get the values for read only fields from session
                MergeNewValuesWithOriginal(model.CountryItem);
                //***************************************************************************************************************************
            }

            SetAccessContext(model);

            return(model);
        }
コード例 #15
0
 private static Drzava convertViewModelToEntity(CountryVM viewModel)
 {
     return(new Drzava
     {
         IDDrzava = viewModel.IDCountry,
         Naziv = Utils.GetCleanTitleString(viewModel.Name)
     });
 }
コード例 #16
0
        //
        // GET: /SysAdmin/Country/Create
        public ActionResult Create()
        {
            CountryVM viewModel = new CountryVM();

            //AcademicYearBAL academicYearBAL = new AcademicYearBAL();
            // viewModel.AcademicYears = from obj in academicYearBAL.GetAll() select new SelectListItem() { Text = obj.AcademicYearName, Value = obj.AcademicYearId.ToString() };
            viewModel.Status = true;
            return(View(viewModel));
        }
コード例 #17
0
        public ActionResult Edit()
        {
            // Retrieve ID from session
            string code = SessionManager.CountryCode;

            CountryVM model = new CountryVM();

            // Not from staff or error
            if (String.IsNullOrEmpty(code))
            {
                //If session has lists then use them
                RepopulateListsFromCacheSession(model);

                //Assume we are in create mode as no code passed
                model.CountryItem = new CountryModel()
                {
                    IsActive = true
                };
            }
            //if we have been passed a code then assume we are in edit situation and we need to retrieve from the database.
            else
            {
                // Create service instance
                AdminServiceClient sc = new AdminServiceClient();

                try
                {
                    // Call service to get Country item and any associated lookups
                    CountryVMDC returnedObject = sc.GetCountry(CurrentUser, CurrentUser, appID, "", code);

                    // Close service communication
                    sc.Close();

                    //Get view model from service
                    model = ConvertCountryDC(returnedObject);

                    ResolveFieldCodesToFieldNamesUsingLists(model);

                    //Store the service version
                    SessionManager.CountryServiceVersion = model.CountryItem;
                }
                catch (Exception e)
                {
                    // Handle the exception
                    string message = ExceptionManager.HandleException(e, sc);
                    model.Message = message;

                    return(View(model));
                }
            }

            //Adds current retrieved Country to session
            SessionManager.CurrentCountry = model.CountryItem;
            SetAccessContext(model);

            return(View(model));
        }
コード例 #18
0
 public ActionResult Edit(int?id)
 {
     ViewData["RegionList"] = DatabaseContext.RegionRepository.GetAll();
     if (id.HasValue)
     {
         CountryVM model = DatabaseContext.CountryRepository.Get(id.Value);
         return(View(model));
     }
     return(View());
 }
コード例 #19
0
 public int Create(CountryVM countryVM)
 {
     parameters.Add("name", countryVM.Name);
     using (var connection = new SqlConnection(_connectionString.Value))
     {
         var items = connection.Execute("SP_InsertCountry",
                                        parameters, commandType: CommandType.StoredProcedure);
         return(items);
     }
 }
コード例 #20
0
        public IActionResult Put(CountryVM countryVM)
        {
            var data = _countryService.Update(countryVM);

            if (data > 0)
            {
                return(Ok(data));
            }
            return(BadRequest("Failed"));
        }
コード例 #21
0
        public ActionResult Create(CountryVM countryVm)
        {
            if (ModelState.IsValid)
            {
                _bll.Add(countryVm);
                return(RedirectToAction("Index"));
            }

            return(View(countryVm));
        }
コード例 #22
0
        private void SetFlagsFalse(CountryVM model)
        {
            model.IsExitConfirmed = "False";
            model.IsNewConfirmed  = "False";

            //Stop the binder resetting the posted values
            ModelState.Remove("IsDeleteConfirmed");
            ModelState.Remove("IsExitConfirmed");
            ModelState.Remove("IsNewConfirmed");
        }
コード例 #23
0
        public Dashboard GetDashboard()
        {
            var model = new Dashboard();

            model.NewMembers  = _ctx.Customer.Count();
            model.Technicians = _ctx.Technicals.Count();
            model.sales       = _ctx.OrderItems.Count();
            var orderItems    = _ctx.OrderItems.ToList();
            var orderServices = _ctx.OrderServices.ToList();

            model.Services = orderServices.Count();

            model.TechnicalsVM = (from users in _ctx.Users.Where(ent => ent.IsActive && !ent.IsDeleted && ent.JobTitleId == (int)En_JobTitle.Technical)
                                  select new TechnicalsVM
            {
                ArabicName = users.ArabicName,
                EnglishName = users.EnglishName,
                OnWork = _ctx.Orders.FirstOrDefault(ent => ent.ResponsibleUserId == users.Id && ent.DeliverDate == DateTime.Now) != null,
                Lat = users.Lat,
                Long = users.Long,
                Online = users.OnLine
            }
                                  ).ToList();
            model.ItemsVM = (from item in _ctx.Item.Where(ent => ent.IsActive && !ent.IsDeleted)
                             join images in _ctx.ItemImages.Take(1) on item.Id equals images.ItemId
                             select new ItemsVM
            {
                ArabicName = item.ArabicName,
                EnglishName = item.EnglishName,
                ImagePath = images.ImagePath,
                Price = item.Price,
                Sales = orderItems.Where(ent => ent.OrderId == item.Id).Sum(ent => ent.Price)
            }).ToList();
            model.ServeicesVM = (from item in _ctx.Services.Where(ent => ent.IsActive && !ent.IsDeleted)
                                 select new ServeicesVM
            {
                ArabicName = item.ArabicName,
                EnglishName = item.EnglishName,
                Sales = orderServices.Where(ent => ent.ServiceId == item.Id).Sum(ent => ent.Price)
            }).ToList();
            model.ItemesChart    = GetTotalSales();
            model.ServeicesChart = GetTotalServeices();
            model.CountryVM      = new List <CountryVM>();
            var countries = _ctx.City.Where(ent => ent.IsActive && !ent.IsDeleted);

            foreach (var item in countries)
            {
                var city = new CountryVM();
                city.ArabicName  = item.ArabicName;
                city.EnglishName = item.EnglishName;
                city.Total       = _ctx.Users.Where(ent => ent.CityId == item.Id && ent.JobTitleId != (int)En_JobTitle.Technical).Count();
                model.CountryVM.Add(city);
            }
            return(model);
        }
コード例 #24
0
        public CountryVM SaveCountrys(CountryVM Countrys)
        {
            try
            {
                if (!Countrys.EditFlag)
                {
                    ds = _EzBusinessHelper.ExecuteDataSet("Select count(*) as [count1] from Country where CmpyCode='" + Countrys.CmpyCode + "' and Code='" + Countrys.Code + "'");
                    dt = ds.Tables[0];


                    int Countrys1 = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        Countrys1 = int.Parse(dr["count1"].ToString());
                    }

                    if (Countrys1 == 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("'" + Countrys.CmpyCode + "',");
                        sb.Append("'" + Countrys.Code + "',");
                        sb.Append("'" + Countrys.Name + "',");
                        sb.Append("'" + Countrys.UniCodeName + "')");
                        _EzBusinessHelper.ExecuteNonQuery("insert into Country(CmpyCode,Code,Name,UniCodeName) values(" + sb.ToString() + "");
                        Countrys.SaveFlag     = true;
                        Countrys.ErrorMessage = string.Empty;
                    }
                    else
                    {
                        Countrys.SaveFlag     = false;
                        Countrys.ErrorMessage = "Duplicate Record";
                    }
                    return(Countrys);
                }
                var CountrysEdit = _EzBusinessHelper.ExecuteScalar("Select count(*) from Country where CmpyCode='" + Countrys.CmpyCode + "' and Code='" + Countrys.Code + "'");
                if (CountrysEdit != 0)
                {
                    _EzBusinessHelper.ExecuteNonQuery("update Country set CmpyCode='" + Countrys.CmpyCode + "',Code='" + Countrys.Code + "',Name='" + Countrys.Name + "',UniCodeName='" + Countrys.UniCodeName + "' where CmpyCode='" + Countrys.CmpyCode + "' and Code='" + Countrys.Code + "'");
                    Countrys.SaveFlag     = true;
                    Countrys.ErrorMessage = string.Empty;
                }
                else
                {
                    Countrys.SaveFlag     = false;
                    Countrys.ErrorMessage = "Record not available";
                }
            }
            catch
            {
                Countrys.SaveFlag = false;
                //  unit.ErrorMessage = exceptionMessage;
            }

            return(Countrys);
        }
コード例 #25
0
        public IActionResult SaveCountry(CountryVM CountryVM)
        {
            TransactionResult <List <CountryVM> > result = _UserOperations.BL_SaveCountry(CountryVM);

            if (!result.Success)
            {
                return(BadRequest(new { message = result.Message }));
            }

            return(Ok(result.Data));
        }
コード例 #26
0
        public CountryVM Create(CountryVM Entity)
        {
            var entity = iMapper.Map <CountryVM, Country>(Entity);
            var Result = iMapper.Map <Country, CountryVM>(unitOfWork.CountryRepository.add(entity));

            if (Result != null)
            {
                CacheManager <List <CountryVM> > .RemoveItemFromCache(NameCache);
            }
            return(Result);
        }
コード例 #27
0
        public async Task <IActionResult> Create([Bind("Name, Code")] CountryVM country)
        {
            if (ModelState.IsValid)
            {
                await service.AddCountryAsync(country.Adapt <CountryDTO>());

                return(RedirectToAction(nameof(Index)));
            }

            return(View(country));
        }
コード例 #28
0
        public ActionResult Update(int id)
        {
            if ((string)Session["user"] != "admin")
            {
                return(RedirectToAction("../Home/Login"));
            }
            var       country   = _countryManager.GetById(id);
            CountryVM countryVM = Mapper.Map <CountryVM>(country);

            return(View(countryVM));
        }
コード例 #29
0
        public async Task <CountryVM> CreateAsync(CountryVM Country)
        {
            var newCountry = iMapper.Map <CountryVM, Country>(Country);
            var Result     = iMapper.Map <Country, CountryVM>(await unitOfWork.CountryRepository.addAsyc(newCountry));

            if (Result != null)
            {
                CacheManager <List <CountryVM> > .RemoveItemFromCache(NameCache);
            }
            return(Result);
        }
コード例 #30
0
        public CountryVM Put(CountryVM country)
        {
            var newCountryVM = iMapper.Map <CountryVM, Country>(country);
            var Result       = iMapper.Map <Country, CountryVM>(unitOfWork.CountryRepository.AddOrUpdate(newCountryVM));

            if (Result != null)
            {
                CacheManager <List <CountryVM> > .RemoveItemFromCache(NameCache);
            }
            return(Result);
        }