Example #1
0
        public bool AddOrUpdate(UserVO userVO, EmployerVO employerVO, BusinessVO businessVO)
        {
            var q = (from us in db.Users
                     where us.Id == userVO.Id
                     select us).FirstOrDefault();

            try
            {
                if (q == null)
                {
                    us.Add(userVO);
                    base.Add(employerVO);
                    bs.Add(businessVO);
                }
                else
                {
                    us.Update(userVO);
                    base.Update(employerVO);
                    bs.Update(businessVO);
                }
                return(true);
            }
            catch (Exception)
            {
                this.UndoChanges();
                return(false);
            }
        }
        public void ProcessEndTest()
        {
            StudentTestBusinessObject @new = TestDetailsBusinessObject.TestDetails;

            @new.RecordId = -1;
            @new.Start    = TestDetailsBusinessObject.DateStart;
            @new.End      = DateTime.Now;
            studentTests.Add(@new);
        }
        public async Task <IActionResult> Add([FromBody] BusinessModel model)
        {
            try
            {
                var response = await _service.Add(model);

                if (!response.IsSuccessful)
                {
                    return(BadRequest(response));
                }
                return(Ok(response));
            }
            catch
            {
                return(StatusCode(500, "Internal Server Error."));
            }
        }
        public string UploadFileWithTarget(string filename, string targetFilename, Stream stream)
        {
            OperationResult result = new OperationResult(true);

            try
            {
                string FilePath = Path.Combine(HostingEnvironment.MapPath("~/Resources/Uploads"), targetFilename);

                int length = 0;
                using (FileStream writer = new FileStream(FilePath, FileMode.Create))
                {
                    int readCount;
                    var buffer = new byte[8192];
                    while ((readCount = stream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        writer.Write(buffer, 0, readCount);
                        length += readCount;
                    }
                }


                IBusinessService businessService = Factory.Create <IBusinessService>(Keywords.UPLOADEDFILE, ClassType.clsTypeBusinessService);
                object           dataObject      = Factory.Create <object>(Keywords.UPLOADEDFILE, ClassType.clsTypeDataModel);

                UploadedFileForm formUpload = new UploadedFileForm();
                formUpload.FileSize         = length;
                formUpload.OriginalFileName = filename;
                formUpload.TargetFileName   = targetFilename;
                formUpload.UserId           = 1;
                formUpload.UploadedDate     = DateTime.Now;

                UploadedFileFormDataConverter formDataConverter = new UploadedFileFormDataConverter();
                formDataConverter.PopulateData(formUpload, dataObject);

                result = businessService.Add(dataObject);
            }
            catch (Exception err)
            {
                result = new OperationResult(false, err);
            }

            return(Serializer.Json.Serialize(result));
        }
        public OperationResult Add(DataForm formObject)
        {
            OperationResult result = new OperationResult(true, formObject);

            //formValidator = Factory.Create<IFormValidator>(this.Key, ClassType.clsTypeFormValidator);
            ValidationResult validationResult = formValidator.Validate(formObject);

            if (validationResult.Result)
            {
                formDataConverter = Factory.Create <IFormDataConverter>(this.Key, ClassType.clsTypeFormProcessor);
                Object o = Factory.Create <Object>(this.Key, ClassType.clsTypeDataModel);
                formDataConverter.PopulateData(formObject, o);

                businessService = Factory.Create <IBusinessService>(this.Key, ClassType.clsTypeBusinessService);
                result          = businessService.Add(o);
            }
            else
            {
                result.Result  = false;
                result.Message = "Validation Error";
                result.Data    = validationResult;
            }
            return(result);
        }
Example #6
0
        public ActionResult AddBusiness(BusinessViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty;
                var admin          = MembershipService.Get(loggedOnUserId);
                var settings       = SettingsService.GetSettings();

                var businessToAdd = new Business
                {
                    Name          = viewModel.Name,
                    PhysicalCity  = viewModel.PhysicalCity,
                    PhysicalState = viewModel.PhysicalState,
                    Active        = false,
                    Completed     = false
                };

                StatesViewModel statesViewModel = new StatesViewModel()          //Load static State dropdown
                {
                    allStates = SettingsService.ListOfStates().ToList()
                };
                viewModel._stateViewModel = statesViewModel;

                //ToDo:
                //1)check if name is duplicate
                //2)
                //var createStatus = _businessService.AdminCreateBusiness(businessToAdd, loggedOnUserId);
                var business = _businessService.GetByName(viewModel.Name);
                if (business == null)
                {
                    try
                    {
                        business = _businessService.Add(businessToAdd);
                        _businessService.AdminBusinessAdded(businessToAdd, admin);
                        unitOfWork.Commit();
                        TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel
                        {
                            Message     = "Business Added.",
                            MessageType = GenericMessages.success
                        };
                        return(RedirectToAction("UpdateBusiness", "AdminBusiness", new { id = business.Id }));
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        //LoggingService.Error(ex);
                        TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel
                        {
                            Message     = "Adding a business failed.",
                            MessageType = GenericMessages.danger
                        };
                    }
                }
                else
                {
                    TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel
                    {
                        Message     = "Duplicate business name.  Add failed.",
                        MessageType = GenericMessages.danger
                    };
                }
            }
            return(View(viewModel));
        }