Example #1
0
        public IHttpActionResult PostAddCompany(Company comp)
        {
            //checking sa username
            var userExist = db.tblUserManagements.Where(u => u.UserName == comp.Username);

            if (userExist.Count() > 0)
            {
                return(BadRequest());
            }
            else
            {
                tblUserManagement user = new tblUserManagement();
                user.UserName    = comp.Username;
                user.Password    = comp.Password;
                user.RoleId      = "2";
                user.UsersId     = Guid.NewGuid().ToString("N").Substring(0, 5).ToUpper();
                user.DateCreated = DateTime.Now;
                user.Status      = 1;

                db.Entry(user).State = EntityState.Added;

                tblBranchShop branch = new tblBranchShop();
                branch.BranchName   = comp.BranchName;
                branch.EmailAddress = comp.EmailAddress;
                branch.Address      = comp.Address;
                branch.userID       = user.UsersId;
                branch.BranchId     = Guid.NewGuid().ToString("N").Substring(0, 5).ToUpper();

                db.Entry(branch).State = EntityState.Added;

                db.SaveChanges();

                return(Ok());
            }
        }
        public async Task <IHttpActionResult> PuttblBranchShop(int id, tblBranchShop tblBranchShop)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblBranchShop.recNo)
            {
                return(BadRequest());
            }

            db.Entry(tblBranchShop).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblBranchShopExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GettblBranchShop(int id)
        {
            tblBranchShop tblBranchShop = await db.tblBranchShops.FindAsync(id);

            if (tblBranchShop == null)
            {
                return(NotFound());
            }

            return(Ok(tblBranchShop));
        }
        public async Task <IHttpActionResult> DeletetblBranchShop(int id)
        {
            tblBranchShop tblBranchShop = await db.tblBranchShops.FindAsync(id);

            if (tblBranchShop == null)
            {
                return(NotFound());
            }

            db.tblBranchShops.Remove(tblBranchShop);
            await db.SaveChangesAsync();

            return(Ok(tblBranchShop));
        }
        public async Task <IHttpActionResult> PosttblBranchShop(tblBranchShop tblBranchShop)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            tblBranchShop.BranchId = Guid.NewGuid().ToString().Replace("-", string.Empty).Replace("+", string.Empty).Substring(0, 5).ToUpper();
            tblBranchShop.Status   = 1;

            db.tblBranchShops.Add(tblBranchShop);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = tblBranchShop.recNo }, tblBranchShop));
        }