示例#1
0
        public static string DeleteDepartment(string dep_id, string user_id, string RequestID)
        {
            //Security Check
            if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "delete"))
            {
                throw new Exception("No Access.");
            }

            LINQ_MasterDataContext dc = new LINQ_MasterDataContext();

            try
            {
                Mst_Department dep = new Mst_Department();
                dep = (from c in dc.Mst_Departments where c.DepartmentID == dep_id && c.Active == true select c).FirstOrDefault();
                if (dep == null)
                {
                    return("Error~We can't find");
                }
                dep.Active     = false;
                dep.ModifiedOn = DateTime.Now;
                dep.ModifiedBy = user_id;
                dep.LastAction = Guid.NewGuid().ToString();
                dc.SubmitChanges(ConflictMode.ContinueOnConflict);
                return("Success~");
            }
            catch (ChangeConflictException ex)
            {
                return("Success~");
            }
        }
示例#2
0
        public static string SaveDepartment(string dep_id, string user_id, string department_name, string notifyemail, string protocol, string description, string remark, string RequestID)
        {
            try
            {
                LINQ_MasterDataContext dc         = new LINQ_MasterDataContext();
                Mst_Department         the_record = new Mst_Department();
                if (dep_id == "" || dep_id == null)
                {
                    the_record = (from c in dc.Mst_Departments where c.DepartmentName == department_name && c.Active == true && ((dep_id == "") || (dep_id != "" && c.DepartmentID != dep_id)) select c).FirstOrDefault();
                    if (the_record == null)
                    {
                        //Security Check
                        if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "create"))
                        {
                            throw new Exception("No Access.");
                        }

                        the_record = new Mst_Department()
                        {
                            CreatedBy    = user_id,
                            CreatedOn    = DateTime.Now,
                            Active       = true,
                            DepartmentID = Guid.NewGuid().ToString(),
                            LastAction   = Guid.NewGuid().ToString()
                        };
                        dc.Mst_Departments.InsertOnSubmit(the_record);
                        dep_id = the_record.DepartmentID;
                    }
                    else
                    {
                        return("Error~Duplicate Department Name");
                    }
                }
                else
                {
                    //Security Check
                    if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "update"))
                    {
                        throw new Exception("No Access.");
                    }

                    the_record = (from c in dc.Mst_Departments where c.DepartmentID == dep_id select c).FirstOrDefault();
                    if (the_record == null)
                    {
                        throw new Exception("System cannot find the record");
                    }
                }
                the_record.ModifiedBy     = user_id;
                the_record.ModifiedOn     = DateTime.Now;
                the_record.LastAction     = Guid.NewGuid().ToString();
                the_record.DepartmentName = department_name;
                the_record.NotifyEmail    = notifyemail;
                the_record.Protocol       = string.IsNullOrEmpty(protocol) ? 0:Convert.ToDecimal(protocol);
                the_record.Description    = string.IsNullOrEmpty(description) ? "" : description.Replace("%27", "");
                the_record.Remark         = string.IsNullOrEmpty(remark) ? "" : remark.Replace("%27", "");
                dc.SubmitChanges();
                return("Success~" + the_record.DepartmentID);
            }
            catch (Exception ex)
            {
                return("Error~" + ex.Message);
            }
        }