コード例 #1
0
        public IActionResult Save(CompanyIndexViewModel model)
        {
            var UserId = HttpContext.Session.GetString("UserId");

            if (ModelState.IsValid)
            {
                var company = new Company
                {
                    Id          = model.Id,
                    Description = model.Description,
                };
                if (model.Id.ToString().Length <= 0 || model.Id == 0)
                {
                    company.CreatedBy    = UserId;
                    company.CreationDate = DateTime.Now;
                    _Company.Add(company);
                }
                else
                {
                    company.ModifiedBy   = UserId;
                    company.ModifiedDate = DateTime.Now;
                    _Company.Update(company);
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index", model));
            }
        }
コード例 #2
0
 public IActionResult Create(ArticleContent article)
 {
     if (ModelState.IsValid)
     {
         // Add The New Article Contents To SQLite Database
         company.Add(article);
         return(RedirectToActionPermanent("Dashboard"));
     }
     return(View());
 }
コード例 #3
0
 public async Task <ActionResult <Company> > AddNewCompany([FromBody] Company newCompany)
 {
     if (_companyService.Add(newCompany))
     {
         var company = _companyService.GetInserted();
         // TODO: da se vraca kompanija koja je dodat kao objekat
         return(Created("", company));
     }
     return(Forbid("Nemoguce uneti novu kompaniju!"));
 }
コード例 #4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await userManager.GetUserAsync(User);

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            await Task.Run(() =>
            {
                Company.company_create_date = DateTime.Now;
            });

            db.Add(Company);
            await db.CommitAsync();

            await Task.Run(() =>
            {
                user.CompanyID = Company.companyId;
            });

            if (Imgfile != null)
            {
                CompanyPicInfo = CompanyPicInfo == null ? new CompanyPicture() : CompanyPicInfo;
                //Upload to file system
                string uploadsFolder  = Path.Combine(env.WebRootPath, "img");
                string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + Imgfile.FileName);
                string filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                //Update database
                await Task.Run(() =>
                {
                    CompanyPicInfo.Path      = uniqueFileName;
                    CompanyPicInfo.imageType = ImageType.Icon;
                    CompanyPicInfo.CompanyId = Company.companyId;
                });

                picdb.AddIcon(CompanyPicInfo);
                await picdb.CommitAsync();

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await Imgfile.CopyToAsync(fileStream);
                }
            }

            await userManager.UpdateAsync(user);

            await signInManager.RefreshSignInAsync(user);

            TempData["CompanyStatus"] = "Your company profile has been created!";
            return(RedirectToPage("./Index"));
        }
コード例 #5
0
        /// <summary>
        /// 系统初始化默认单位
        /// </summary>
        public static void InitSystemDefaultCompany()
        {
            try
            {
                ICompany factory    = CompanyFactory.GetFactory();
                bool     hasCompany = factory.SystemExistCompany();
                if (!hasCompany)
                {
                    using (DbOperator dbOperator = ConnectionManager.CreateConnection())
                    {
                        try
                        {
                            dbOperator.BeginTransaction();
                            BaseCompany compamy = GetCompanyModel();
                            bool        result  = factory.Add(compamy, dbOperator);
                            if (!result)
                            {
                                throw new MyException("添加默认单位失败");
                            }

                            result = SysUserServices.AddCompanyDefaultUser(compamy, dbOperator);

                            if (!result)
                            {
                                throw new MyException("添加默认用户失败");
                            }

                            dbOperator.CommitTransaction();
                        }
                        catch
                        {
                            dbOperator.RollbackTransaction();
                            throw;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "添加系统默认单用户失败");
            }
        }
コード例 #6
0
        public static bool Add(BaseCompany model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    model.CPID = GuidGenerator.GetGuid().ToString();
                    ICompany    factory = CompanyFactory.GetFactory();
                    BaseCompany dbModel = factory.QueryCompanyByCompanyName(model.CPName);
                    if (dbModel != null)
                    {
                        throw new MyException("系统已存在相同单位名称的单位");
                    }

                    bool result = factory.Add(model, dbOperator);

                    result = SysUserServices.AddCompanyDefaultUser(model, dbOperator);
                    if (!result)
                    {
                        throw new MyException("添加默认用户失败");
                    }

                    dbOperator.CommitTransaction();
                    if (result)
                    {
                        OperateLogServices.AddOperateLog <BaseCompany>(model, OperateType.Add);
                    }
                    return(result);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
コード例 #7
0
        public override async Task <UpsertCompanyResponse> AddCompany(CompanyRequest request, ServerCallContext context)
        {
            PredlaganjeSaradnjeIRC.Data.Model.Company company =
                _mapper.Map <PredlaganjeSaradnjeIRC.Data.Model.Company>(request);

            PredlaganjeSaradnjeIRC.Data.Model.Location location =
                _mapper.Map <PredlaganjeSaradnjeIRC.Data.Model.Location>(request.Location);

            PredlaganjeSaradnjeIRC.Data.Model.Contact contact =
                _mapper.Map <PredlaganjeSaradnjeIRC.Data.Model.Contact>(request.Contact);

            company.Locations = new List <PredlaganjeSaradnjeIRC.Data.Model.Location> {
                location
            };
            company.Contacts = new List <PredlaganjeSaradnjeIRC.Data.Model.Contact> {
                contact
            };

            if (_companyService.Add(company))
            {
                var createdCompany = _companyService.GetInserted();

                _logger.LogInformation("company created");

                return(new UpsertCompanyResponse
                {
                    Status = StatusCode.Ok,
                    Message = "Kompanija je kreirana",
                    Company = _mapper.Map <CompanyResponse>(createdCompany),
                    Contact = _mapper.Map <ContactResponse>(createdCompany.Contacts.LastOrDefault()),
                    Location = _mapper.Map <LocationResponse>(createdCompany.Locations.LastOrDefault())
                });
            }

            _logger.LogError("company can't be created");
            return(new UpsertCompanyResponse
            {
                Status = StatusCode.Error,
                Message = "Nije moguce kreirati kompaniju"
            });
        }
コード例 #8
0
 public IActionResult Save(CompanyViewModel model)
 {
     if (ModelState.IsValid)
     {
         var company = new Company
         {
             Id          = model.Id,
             Description = model.Description,
         };
         if (model.Id.ToString().Length <= 0)
         {
             _Company.Add(company);
         }
         else
         {
             _Company.Update(company);
         }
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
コード例 #9
0
        /// <summary>
        /// 系统初始化默认单位CS
        /// </summary>
        public static bool InitSystemDefaultCompanyCS(string VName, string CPName, string userno, string pwd, string systemmodelpath)
        {
            try
            {
                ICompany factory = CompanyFactory.GetFactory();
                using (DbOperator dbOperator = ConnectionManager.CreateConnection())
                {
                    try
                    {
                        dbOperator.BeginTransaction();
                        BaseCompany compamy = GetCompanyModel();
                        compamy.CPName       = CPName;
                        compamy.UserAccount  = userno;
                        compamy.UserPassword = pwd;
                        bool result = factory.Add(compamy, dbOperator);
                        if (!result)
                        {
                            throw new MyException("添加默认单位失败");
                        }
                        BaseVillage village = GetVillage(compamy.CPID);
                        village.VName = VName;
                        result        = VillageServices.AddVillageDefaultUser(village, dbOperator);
                        if (!result)
                        {
                            throw new MyException("添加默认小区失败");
                        }
                        result = SysUserServices.AddCompanyDefaultUserCS(compamy, village, dbOperator, systemmodelpath);
                        if (!result)
                        {
                            throw new MyException("添加默认用户失败");
                        }

                        BaseParkinfo parkinfo = GetParkinfo(village.VID);
                        result = ParkingServices.AddParkinfoDefault(parkinfo, dbOperator);
                        if (!result)
                        {
                            throw new MyException("添加默认车场失败");
                        }
                        dbOperator.CommitTransaction();

                        ParkArea area = GetParkArea(parkinfo.PKID);
                        result = ParkAreaServices.AddDefualt(area);
                        if (result)
                        {
                            ParkBox box = GetParkBox(area.AreaID);
                            result = ParkBoxServices.AddDefault(box);
                            if (result)
                            {
                                result = ParkGateServices.AddDefault(GetParkGate(box.BoxID, 1));
                                result = ParkGateServices.AddDefault(GetParkGate(box.BoxID, 2));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        dbOperator.RollbackTransaction();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "添加系统默认单用户失败");
                return(false);
            }
            return(true);
        }
コード例 #10
0
 public void Add(CompanyTBL companyTBL)
 {
     _compRespository.Add(companyTBL);
 }
コード例 #11
0
 public static bool Add(CompanyInfo companyInfo)
 {
     return(dal.Add(companyInfo));
 }
コード例 #12
0
ファイル: BCompany.cs プロジェクト: zhr008/ERP-1
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(BaseCompanyTable model)
 {
     return(dal.Add(model));
 }
コード例 #13
0
ファイル: CompanyApp.cs プロジェクト: Berbecut/08_ManageStore
 public async Task Add(Core.Models.Company entity)
 {
     await _company.Add(entity);
 }
コード例 #14
0
ファイル: CompanyController.cs プロジェクト: rbgx/PunchClock
        public ActionResult Register(CompanyRegister companyRegister, HttpPostedFileBase logo)
        {
            if (_userService.Get(userName: companyRegister.CreatedBy.UserName).Any())
            {
                ModelState.AddModelError("",
                                         $"Username {companyRegister.CreatedBy.UserName} is already in use. Please try with a different username");
                return(View(companyRegister));
            }

            // need to handle the file size
            if (logo != null && logo.ContentLength > 0 && logo.ContentType.Contains("image"))
            {
                using (Stream inputStream = logo.InputStream)
                {
                    MemoryStream memoryStream = inputStream as MemoryStream;
                    if (memoryStream == null)
                    {
                        memoryStream = new MemoryStream();
                        inputStream.CopyTo(memoryStream);
                    }
                    companyRegister.Company.LogoUrl    = logo.FileName;
                    companyRegister.Company.LogoBinary = memoryStream.ToArray();
                }
            }
            companyRegister.CreatedBy.UserRegisteredIp     = UserSession.IpAddress;
            companyRegister.CreatedBy.RegisteredMacAddress = UserSession.MacAddress;
            companyRegister.CreatedBy.LastActivityIp       = UserSession.IpAddress;
            companyRegister.CreatedBy.LastActiveMacAddress = UserSession.MacAddress;
            companyRegister.CreatedBy.EmploymentTypeId     = (int)EmploymentType.FullTime;

            companyRegister.Company.Id = _companyService.Add(companyRegister.Company);

            if (companyRegister.Company.Id == (int)RegistrationStatus.DuplicateCompany)
            {
                ModelState.AddModelError("", $"Company {companyRegister.CreatedBy.UserName} is already registerted");
                return(View(companyRegister));
            }
            if (companyRegister.Company.Id < 1)
            {
                ViewBag.Message = "Sorry. Failed to Add your company";
                return(View(companyRegister));
            }

            companyRegister.CreatedBy.CompanyId = companyRegister.Company.Id;
            try
            {
                var result = UserManager.CreateAsync(companyRegister.CreatedBy, companyRegister.CreatedBy.Password)
                             .Result;
                if (result.Succeeded)
                {
                    //SignInManager.SignIn(companyRegister.CreatedBy, isPersistent: false, rememberBrowser: false);
                    _userService.AddAddress(companyRegister.CreatedBy.RegistrationAddress);
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error);
                    }
                    return(View(companyRegister));
                }
            }
            catch
            {
                // ignored
            }

            if (companyRegister.Company.Id > 0)
            {
                _companyService.SetCreatedBy(companyId: companyRegister.Company.Id,
                                             userId: companyRegister.CreatedBy.Id);
                ViewBag.Message = "Your company code <strong>" + companyRegister.Company.RegisterCode +
                                  "</strong>. Your employees need this code to sign up for their account.";
#pragma warning disable 4014
                SignInManager.SignInAsync(companyRegister.CreatedBy, isPersistent: false,
#pragma warning restore 4014
                                          rememberBrowser: false);

                string emailMessage = _companyService.ComposeRegisteredEmail(companyRegister);
                _emailService.SendEmail(emailMessage, "Successfully Registered", new[] { companyRegister.CreatedBy.Email });
                return(RedirectToAction("Index", "Home"));
            }
            return(View(companyRegister));
        }
 protected override string Execute(ICompany company, IFurniture furniture)
 {
     company.Add(furniture);
     return(string.Format(Messages.FurnitureAddedSuccessMessage, furniture.Model, company.Name));
 }