Пример #1
0
        public ActionResult Create(OfficeModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.CreatedDate = DateTime.Now;

                    officeService.Add(model);

                    TempData["Success"] = $"{model.OfficeName} Added !";

                    return(RedirectToAction("Index"));
                }

                model.OfficeTypeList = dynamicList.GetOfficeTypeList();

                return(View(@"~\Views\Configuration\Office\Create.cshtml", model));
            }
            catch (Exception e)
            {
                TempData["Danger"] = $"Opppsss something went wrong {e.Message}";

                throw;
            }
        }
Пример #2
0
        private bool InsertOfficeToDb(DMOffice Office, Guid userGuid)
        {
            var entity = MapOfficeToCoreOffice(Office, userGuid);

            _officeService.Add(entity);
            return(true);
        }
Пример #3
0
        public IActionResult Add([FromBody] OfficeViewModel officeViewModel)
        {
            try
            {
                var officeModel = Models.ObjectMapper <OfficeViewModel, Office> .Map(officeViewModel);

                if (_officeService.CheckDuplicate(officeModel) > 0)
                {
                    var errorMessage = "Duplicate value entered for either code or name !!";
                    ModelState.AddModelError("", errorMessage);
                    return(BadRequest(ModelState));
                }
                if (ModelState.IsValid)
                {
                    Guid id = Guid.NewGuid();
                    officeModel.OfficeGuid = id;
                    officeModel.CreatedOn  = CurrentDateTimeHelper.GetCurrentDateTime();
                    officeModel.CreatedBy  = id;
                    officeModel.UpdatedOn  = CurrentDateTimeHelper.GetCurrentDateTime();
                    officeModel.UpdatedBy  = id;
                    officeModel.IsActive   = true;
                    officeModel.IsDeleted  = false;
                    _officeService.Add(officeModel);


                    //audit log..
                    var additionalInformation = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Added.ToString(), ResourceType.Office.ToString());
                    //var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + ("/Office/Details/" + officeModel.OfficeGuid);
                    var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + "/admin/office";

                    var additionalInformationWithUri = string.Format("<a href=\"{0}\">{1}</a>", additionalInformationURl, additionalInformation);

                    var resource = string.Format("{0} </br> GUID:{1} </br> Office Name:{2} </br> Office Code:{3}", ResourceType.Office.ToString(), officeModel.OfficeGuid, officeModel.OfficeName, officeModel.OfficeCode);

                    AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), officeModel, resource, officeModel.OfficeGuid, UserHelper.GetHostedIp(HttpContext), "Office Added", Guid.Empty, "Successful", "", additionalInformationWithUri, additionalInformationURl);


                    return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!", office = new { officeGuid = id, officeName = officeModel.OfficeName } }));
                }
                return(BadRequest(ModelState));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(BadRequestFormatter.BadRequest(this, e));
            }
        }
        public IActionResult Post([FromBody] Office office)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }

                _officeContext.Add(office);
                foreach (OfficeNameTranslate item in office.OfficeNameTranlates)
                {
                    item.OfficeId = office.Id;
                    _officeTranslateContext.Add(item);
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
        public async Task <Office> Post([FromBody] Office office)
        {
            var res = await officeContext.Add(office);

            return(res != null ? office : null);
        }
Пример #6
0
        public async Task <IActionResult> Add([FromBody] OfficeModel data)
        {
            var dataEntity = await _officeService.Add(OfficeMapper.Map(data));

            return(Ok(dataEntity));
        }
Пример #7
0
 public IActionResult Add([FromBody] OfficeDTO officeDTO)
 {
     _officeService.Add(officeDTO);
     return(Ok(officeDTO));
 }
Пример #8
0
        public Task <ResourceCreationResult <Office, int> > CreateAsync(Office resource, IRequestContext context, CancellationToken cancellation)
        {
            var newOffice = _officeservice.Add(_toTransportMapper.Map(resource));

            return(Task.FromResult(new ResourceCreationResult <Model.Office, int>(_toResourceMapper.Map(newOffice))));
        }