示例#1
0
        public ActionResult Entry(OrganizationCreateVm entity)
        {
            HttpPostedFileBase file = Request.Files["uploadImage"];

            if (file != null)
            {
                entity.Logo = ConvertToBytes(file);
                if (ModelState.IsValid)
                {
                    var organization  = Mapper.Map <Organization>(entity);
                    var organizations = _organizationManager.GetAllOrganization();
                    if (organizations.FirstOrDefault(x => x.Code == organization.Code) != null)
                    {
                        ViewBag.Message = "Exist";
                        return(View(entity));
                    }
                    else
                    {
                        bool isAdded = _organizationManager.Add(organization);
                        if (isAdded)
                        {
                            ModelState.Clear();
                            ViewBag.Message = "Saved";;
                            return(View());
                        }
                    }
                }
                else
                {
                    ViewBag.Message = "Failed";
                    return(View(entity));
                }
            }

            ModelState.AddModelError("", "An Unknown Error Occured!");
            return(View(entity));
        }