Ejemplo n.º 1
0
        private ResponseModel <Company> Save(int id, Company model)
        {
            //check duplicate for subdomain
            if (model.ScriptFieldCollection?.Count > 0)
            {
                bool hasDuplicate = _context.Companies.Any(t => t.DeletedOn == null && t.SubDomain == model.SubDomain && t.CompanyId != model.CompanyId);

                if (!hasDuplicate)
                {
                    CompanyProvider companyProvider = new CompanyProvider(_context);
                    companyProvider.Save(model);

                    return(new ResponseModel <Company>
                    {
                        Message = id > 0 ? "Successfully updated Company" : "Successfully added Company",
                        StatusCode = 1,
                        ResponseObject = model
                    });
                }
                else
                {
                    return(new ResponseModel <Company>
                    {
                        Message = "Subdomain already exists",
                        StatusCode = 2
                    });
                }
            }
            else
            {
                return(new ResponseModel <Company>
                {
                    Message = "Minimum 1 script field is required",
                    StatusCode = 2
                });
            }
        }