Beispiel #1
0
        public IHttpActionResult SaveOrganization(MultiDataModel multi)
        {
            OrganizationBE data   = JsonConvert.DeserializeObject <OrganizationBE>(multi.String1);
            var            result = OrganizationBL.SaveOrganization(data, multi.Int1, multi.Int2);

            return(Ok(result));
        }
Beispiel #2
0
        public static MessageCustom SaveOrganization(OrganizationBE data, int userId, int nodeId)
        {
            MessageCustom msg = new MessageCustom();

            try
            {
                using (var ts = new TransactionScope())
                {
                    data.i_OrganizationTypeId = 1;
                    string result = OrganizationDal.SaveOrganization(data, userId, nodeId);

                    if (result == null)
                    {
                        msg.Error   = true;
                        msg.Message = "Sucedió un error al guardar la empresa, por favor actualiza y vuelva a intentar";
                        msg.Status  = (int)HttpStatusCode.Conflict;
                    }
                    else
                    {
                        msg.Error   = false;
                        msg.Message = "Se guardó correctamente.";
                        msg.Status  = (int)HttpStatusCode.Created;
                        msg.Id      = result;
                    }

                    ts.Complete();

                    return(msg);
                }
            }
            catch (Exception ex)
            {
                return(msg);
            }
        }
        public static string SaveOrganization(OrganizationBE data, int userId, int nodeId)
        {
            try
            {
                using (var ts = new TransactionScope())
                {
                    string organization = GetOrganizationByRuc(data.v_IdentificationNumber);

                    if (organization != null)
                    {
                        return(organization);
                    }

                    string newId = "";
                    newId = new Common.Utils().GetPrimaryKey(nodeId, 5, "OO");
                    data.v_OrganizationId = newId;
                    data.i_InsertUserId   = userId;
                    data.d_InsertDate     = DateTime.Now;
                    data.i_IsDeleted      = 0;
                    ctx.Organization.Add(data);
                    ctx.SaveChanges();

                    LocationBE loc  = new LocationBE();
                    var        arr  = data.v_Address.Split('-').Reverse().ToArray();
                    var        sede = arr[0].ToString();

                    loc.v_OrganizationId = newId;
                    loc.v_Name           = sede;
                    string locationId = SaveLocationAndGroupOccupation(loc, userId, nodeId);
                    if (locationId == null)
                    {
                        throw new Exception("Error");
                    }

                    ts.Complete();
                    return(newId + "|" + locationId);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }