Esempio n. 1
0
        public ActionResult Delete(SupplierCategory model)
        {
            int result = new SupplierCategoryRepository().DeleteSupplierCategory(model);

            if (result == 0)
            {
                TempData["Success"]          = "Deleted Successfully!";
                TempData["SupCategoryRefNo"] = model.SupCategoryRefNo;
                return(RedirectToAction("Create"));
            }
            else
            {
                if (result == 1)
                {
                    TempData["error"]            = "Sorry!! You Cannot Delete This Supplier Category It Is Already In Use";
                    TempData["SupCategoryRefNo"] = null;
                }
                else
                {
                    TempData["error"]            = "Oops!!..Something Went Wrong!!";
                    TempData["SupCategoryRefNo"] = null;
                }
                return(RedirectToAction("Create"));
            }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Post(SupplierCategory item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            item.ObjectState = ObjectState.Added;
            _service.Insert(item);

            try
            {
                await _unitOfWorkAsync.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ItemExists(item.SupplierCategoryID))
                {
                    return(Conflict());
                }
                throw;
            }

            return(Created(item));
        }
        public int Save(SupplierCategory SupplierCategory)
        {
            SupplierCategory _dbEntry;
            int id = 0;

            if (SupplierCategory.SupplierCategoryID == 0)
            {
                _dbEntry = _context.SupplierCategories.Where(s => s.SupplierID == SupplierCategory.SupplierID).Where(s => s.PartTypeID == SupplierCategory.PartTypeID).FirstOrDefault();
                if (_dbEntry == null)
                {
                    _context.SupplierCategories.Add(SupplierCategory);
                }
                else
                {
                    id = _dbEntry.SupplierCategoryID;
                    _dbEntry.Enabled = true;
                }
            }
            else
            {
                _dbEntry = _context.SupplierCategories.Find(SupplierCategory.SupplierCategoryID);
                if (_dbEntry != null)
                {
                    _dbEntry.SupplierID = SupplierCategory.SupplierID;
                    _dbEntry.PartTypeID = SupplierCategory.PartTypeID;
                    _dbEntry.Enabled    = SupplierCategory.Enabled;
                }
            }
            if (id == 0)
            {
                _context.SaveChanges();
                id = SupplierCategory.SupplierCategoryID;
            }
            return(id);
        }
        public SupplierCategory InsertSupplierCategory(SupplierCategory objSupplierCategory)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                var            result = new SupplierCategory();
                IDbTransaction trn    = connection.BeginTransaction();

                string sql = @"INSERT INTO SupplierCategory(SupCategoryRefNo,SupCategoryName,SupCategoryShortName,CreatedBy,CreatedDate,OrganizationId) 
                                VALUES(@SupCategoryRefNo,@SupCategoryName,@SupCategoryShortName,@CreatedBy,getDate(),@OrganizationId);
                                SELECT CAST(SCOPE_IDENTITY() as int)";

                try
                {
                    int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(SupplierCategory).Name, "0", 1);
                    objSupplierCategory.SupCategoryRefNo = "SUPCAT/" + internalid;

                    int id = connection.Query <int>(sql, objSupplierCategory, trn).Single();
                    objSupplierCategory.SupCategoryId = id;
                    //connection.Dispose();
                    InsertLoginHistory(dataConnection, objSupplierCategory.CreatedBy, "Create", "Supplier Category", id.ToString(), "0");
                    trn.Commit();
                }
                catch (Exception ex)
                {
                    trn.Rollback();
                    objSupplierCategory.SupCategoryId    = 0;
                    objSupplierCategory.SupCategoryRefNo = null;
                }
                return(objSupplierCategory);
            }
        }
Esempio n. 5
0
        public IHttpActionResult PostSupplierCategory(SupplierCategory supplierCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.SupplierCategories.Add(supplierCategory);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (SupplierCategoryExists(supplierCategory.SupplierCategoryID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = supplierCategory.SupplierCategoryID }, supplierCategory));
        }
        public int DeleteSupplierCategory(SupplierCategory objSupplierCategory)
        {
            int result = 0;

            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                string sql = @" Update SupplierCategory Set isActive=0 WHERE SupCategoryId=@SupCategoryId";
                try
                {
                    var id = connection.Execute(sql, objSupplierCategory);
                    objSupplierCategory.SupCategoryId = id;
                    InsertLoginHistory(dataConnection, objSupplierCategory.CreatedBy, "Delete", "Supplier Category", id.ToString(), "0");
                    result = 0;
                }
                catch (SqlException ex)
                {
                    int err = ex.Errors.Count;
                    if (ex.Errors.Count > 0)  // Assume the interesting stuff is in the first error
                    {
                        switch (ex.Errors[0].Number)
                        {
                        case 547:      // Foreign Key violation
                            result = 1;
                            break;

                        default:
                            result = 2;
                            break;
                        }
                    }
                }

                return(result);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Get a list of QueryFilter that represent changed fields.
        /// </summary>
        /// <param name="original">Original Entity. The unchanged entity.</param>
        /// <param name="changed">Changed Entity. The entity holding the changed fields.</param>
        /// <returns>QueryFilters of SupplierCategoryProperty</returns>
        public static QueryFilters <SupplierCategoryProperty> GetChanges(SupplierCategory original, SupplierCategory changed)
        {
            // this method returns a list of changes.
            var changes = new QueryFilters <SupplierCategoryProperty>(5);

            #region Detect Changes
            if (original.SupplierCategoryID != changed.SupplierCategoryID)
            {
                changes.Add(QueryFilter.New(SupplierCategoryProperty.SupplierCategoryID, FilterConditions.Equals, changed.SupplierCategoryID));
            }
            if (string.CompareOrdinal(original.SupplierCategoryName, changed.SupplierCategoryName) != 0)
            {
                changes.Add(QueryFilter.New(SupplierCategoryProperty.SupplierCategoryName, FilterConditions.Equals, changed.SupplierCategoryName));
            }
            if (original.LastEditedBy != changed.LastEditedBy)
            {
                changes.Add(QueryFilter.New(SupplierCategoryProperty.LastEditedBy, FilterConditions.Equals, changed.LastEditedBy));
            }
            if (original.ValidFrom != changed.ValidFrom)
            {
                changes.Add(QueryFilter.New(SupplierCategoryProperty.ValidFrom, FilterConditions.Equals, changed.ValidFrom));
            }
            if (original.ValidTo != changed.ValidTo)
            {
                changes.Add(QueryFilter.New(SupplierCategoryProperty.ValidTo, FilterConditions.Equals, changed.ValidTo));
            }
            #endregion
            return(changes.Count > 0 ? changes : null);
        }
        public string Post(SupplierCategory suplCat)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string    query = @"
                      insert into dbo.SupplierCategory values
                      ('" + suplCat.Category + @"')
                      ";
                    DataTable table = new DataTable();
                    using (var con = new SqlConnection(ConfigurationManager.
                                                       ConnectionStrings["SuppliersERPAppDB"].ConnectionString))
                        using (var cmd = new SqlCommand(query, con))
                            using (var da = new SqlDataAdapter(cmd))
                            {
                                cmd.CommandType = CommandType.Text;
                                da.Fill(table);
                            }

                    return("Added Succesfully!!");
                }
                else
                {
                    var errorMessageList = ModelState.Values.SelectMany(o => o.Errors).Select(e => e.ErrorMessage).ToArray();
                    var errorMessage     = $"Failed to Add!! {string.Join(";", errorMessageList)}";
                    return(errorMessage);
                }
            }
            catch (Exception ex)
            {
                return("Failed to Add!!");
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Compare 2 Entities for changes. NavProperties are NOT taken into account. For NavProperties use the corresponding utils for those Entities
 /// </summary>
 /// <param name="one">Entity One.</param>
 /// <param name="two">Entity Two.</param>
 /// <returns>True if there is changes. False if no changes found.</returns>
 public static bool HasChanges(SupplierCategory one, SupplierCategory two)
 {
     // this method returns true if differences are found between the 2 entities.
     #region Detect Changes
     if (one.SupplierCategoryID != two.SupplierCategoryID)
     {
         return(true);
     }
     if (string.CompareOrdinal(one.SupplierCategoryName, two.SupplierCategoryName) != 0)
     {
         return(true);
     }
     if (one.LastEditedBy != two.LastEditedBy)
     {
         return(true);
     }
     if (one.ValidFrom != two.ValidFrom)
     {
         return(true);
     }
     if (one.ValidTo != two.ValidTo)
     {
         return(true);
     }
     #endregion
     return(false);
 }
Esempio n. 10
0
        public ActionResult Edit(SupplierCategory model)
        {
            model.OrganizationId = OrganizationId;
            model.CreatedDate    = System.DateTime.Now;
            model.CreatedBy      = UserID.ToString();


            var  repo     = new SupplierCategoryRepository();
            bool isexists = repo.IsFieldExists(repo.ConnectionString(), "SupplierCategory", "SupCategoryName", model.SupCategoryName, "SupCategoryId", model.SupCategoryId);

            if (!isexists)

            {
                var result = new SupplierCategoryRepository().UpdateSupplierCategory(model);
                if (result.SupCategoryId > 0)
                {
                    TempData["Success"]          = "Updated Successfully!";
                    TempData["SupCategoryRefNo"] = result.SupCategoryRefNo;
                    return(RedirectToAction("Create"));
                }

                else
                {
                    TempData["error"]            = "Oops!!..Something Went Wrong!!";
                    TempData["SupCategoryRefNo"] = null;
                    return(View("Create", model));
                }
            }
            else
            {
                TempData["error"]            = "This Name Alredy Exists!!";
                TempData["SupCategoryRefNo"] = null;
                return(View("Create", model));
            }
        }
Esempio n. 11
0
        public IHttpActionResult PutSupplierCategory(int id, SupplierCategory supplierCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != supplierCategory.SupplierCategoryID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SupplierCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 12
0
        public ActionResult DeleteConfirmed(int id)
        {
            SupplierCategory supplierCategory = db.SupplierCategories.Find(id);

            db.SupplierCategories.Remove(supplierCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 13
0
        public ActionResult Create()
        {
            ViewBag.Title = "Create";
            SupplierCategory SupplierCategory = new SupplierCategory();

            SupplierCategory.SupCategoryRefNo = new SupplierCategoryRepository().GetRefNo(SupplierCategory);
            return(View(SupplierCategory));
        }
Esempio n. 14
0
 public ActionResult Edit([Bind(Include = "CatId,Name")] SupplierCategory supplierCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplierCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplierCategory));
 }
Esempio n. 15
0
        public IHttpActionResult GetSupplierCategory(int id)
        {
            SupplierCategory supplierCategory = db.SupplierCategories.Find(id);

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

            return(Ok(supplierCategory));
        }
Esempio n. 16
0
 /// <summary>
 /// Merge all values from one Entity into another one.
 /// </summary>
 /// <param name="source">Source Entity. Will be copied to the target.</param>
 /// <param name="target">Target Entity. Will receive the values from the source.</param>
 /// <returns>void.</returns>
 public static void Merge(SupplierCategory source, SupplierCategory target)
 {
     // this method merges 2 Entities.
     #region Merge Values
     target.SupplierCategoryID   = source.SupplierCategoryID;
     target.SupplierCategoryName = source.SupplierCategoryName;
     target.LastEditedBy         = source.LastEditedBy;
     target.ValidFrom            = source.ValidFrom;
     target.ValidTo = source.ValidTo;
     #endregion
 }
Esempio n. 17
0
        public ActionResult Create([Bind(Include = "CatId,Name")] SupplierCategory supplierCategory)
        {
            if (ModelState.IsValid)
            {
                db.SupplierCategories.Add(supplierCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplierCategory));
        }
        public SupplierCategory UpdateSupplierCategory(SupplierCategory objSupplierCategory)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                string sql = @"Update SupplierCategory Set SupCategoryRefNo=@SupCategoryRefNo,SupCategoryName=@SupCategoryName,SupCategoryShortName=@SupCategoryShortName OUTPUT INSERTED.SupCategoryId WHERE SupCategoryId=@SupCategoryId";

                var id = connection.Execute(sql, objSupplierCategory);
                InsertLoginHistory(dataConnection, objSupplierCategory.CreatedBy, "Update", "Supplier Category", id.ToString(), "0");
                return(objSupplierCategory);
            }
        }
Esempio n. 19
0
 private void updateRecord()
 {
     foreach (DataGridViewRow item in gridData.Rows)
     {
         SupplierCategory dep = (SupplierCategory)item.Tag;
         if (dep.ID == m_supcat.ID)
         {
             gridData[0, item.Index].Value = m_supcat.CODE;
             gridData[1, item.Index].Value = m_supcat.NAME;
             break;
         }
     }
 }
Esempio n. 20
0
 private void removeRecord(int id)
 {
     foreach (DataGridViewRow item in gridData.Rows)
     {
         SupplierCategory dep = (SupplierCategory)item.Tag;
         if (dep.ID == id)
         {
             gridData.Rows.Remove(item);
             break;
         }
     }
     gridData.ClearSelection();
 }
Esempio n. 21
0
 public SupplierCategory Put(SupplierCategory item)
 {
     logger.Info("start putCustomer: ");
     try
     {
         return(context.PutSupplierCategory(item));
     }
     catch (Exception ex)
     {
         logger.Error("Error in put supplier category " + ex.Message);
         return(null);
     }
 }
Esempio n. 22
0
 public void ClearForm()
 {
     try
     {
         textBoxCode.Text = "";
         textBoxName.Text = "";
         m_supcat         = new SupplierCategory();
         errorProvider1.Clear();
     }
     catch (Exception x)
     {
         KryptonMessageBox.Show(x.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 23
0
        public IHttpActionResult DeleteSupplierCategory(int id)
        {
            SupplierCategory supplierCategory = db.SupplierCategories.Find(id);

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

            db.SupplierCategories.Remove(supplierCategory);
            db.SaveChanges();

            return(Ok(supplierCategory));
        }
Esempio n. 24
0
        // GET: SupplierCategories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SupplierCategory supplierCategory = db.SupplierCategories.Find(id);

            if (supplierCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(supplierCategory));
        }
Esempio n. 25
0
        public ActionResult ViewSupplierItems(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            SupplierCategory cat = db.SupplierCategories.Find(id);

            if (cat == null)
            {
                return(HttpNotFound());
            }
            return(View(cat));
        }
Esempio n. 26
0
 private void gridData_SelectionChanged(object sender, EventArgs e)
 {
     if (gridData.SelectedRows.Count == 0)
     {
         return;
     }
     ClearForm();
     m_supcat = (SupplierCategory)gridData.SelectedRows[0].Tag;
     if (m_supcat == null)
     {
         return;
     }
     loadData();
     setEnableForm(false);
     setEditMode(EditMode.View);
 }
        public async Task <IResponse> UpdateSupplierCategoryAsync(SupplierCategory entity)
        {
            Logger?.LogInformation("'{0}' has been invoked", nameof(UpdateSupplierCategoryAsync));

            try
            {
                UnitOfWork.Repository <SupplierCategory>().Update(entity);
                await UnitOfWork.SaveChangesAsync();

                return(new Response());
            }
            catch (Exception ex)
            {
                return(new Response(Logger, nameof(UpdateSupplierCategoryAsync), ex));
            }
        }
Esempio n. 28
0
        public ActionResult ViewSupplierItems(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            orderid       = Convert.ToInt32(TempData["id"]);
            TempData["p"] = orderid;
            SupplierCategory cat = db.SupplierCategories.Find(id);

            if (cat == null)
            {
                return(HttpNotFound());
            }
            return(View(cat));
        }
        public ActionResult ViewItems(int id)
        {
            SupplierCategory cat = db.SupplierCategories.Find(id);

            if (cat == null)
            {
                return(HttpNotFound());
            }
            AdminOrder a = new AdminOrder
            {
                OrderId = id
            };

            db.SaveChanges();
            ViewBag.Message = a;
            return(View(cat));
        }
Esempio n. 30
0
        public ActionResult Edit1(int?id, int?idd)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SupplierCategory cat         = db.SupplierCategories.Find(idd);
            SupplierItem     itemsDetail = db.SupplierItems.Find(id);

            Session["imagepath"] = itemsDetail.Image;
            itemsDetail.CatId    = cat.CatId;
            if (itemsDetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CatId = new SelectList(db.SupplierCategories, "CatId", "Name", itemsDetail.CatId);
            return(View(itemsDetail));
        }